Solved

JQuery Web Service call to C# Service

Posted on 2013-11-25
4
335 Views
Last Modified: 2013-12-15
I Have a JQUERY call that is made to a C# web service. My issue is if I use a integer to send to the web service it works fine. When I sent a string value to a different function it does not work.

working script:
C# Service code:

[WebMethod]
    public int JsonTest2(int myparm1, int myparm2)
    {
        return 101;
    }

JQuery Call
 $.ajax({
                        type: "POST",
                        url: "http://localhost:1480/DateWebService.asmx/GetDataFromCookie",
                        data: "{myparm1:105,myparm2:23}",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (msg) {
                            $("#output").text(msg.d);
                        }
                    });


Here is the code that doesn't work...
JQUERY CODE:

 $.ajax({
                        type: "POST",
                        url: "http://localhost:1480/DateWebService.asmx/GetDataFromCookie",
                        data: { SQLStr: "SELECT * FROM mytable", Func: "myfunc" },
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (msg) {
                            $("#output").text(msg.d);
                        }
                    });

JQuery Code:
 [WebMethod]
    public string GetDataFromCookie(string SQLStr, string func)
    {

        return SQLStr;

        //return DateTime.Now.ToString();
    }


please help me learn how to send string instead of integer.
0
Comment
Question by:jeffreyjseaman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 44

Expert Comment

by:Rainer Jeschor
ID: 39676754
Hi,
perhaps just a typo:
In your web method the parameter is named "func" but you provide "Func" (uppercase).
Could you try
                        data: { SQLStr: "SELECT * FROM mytable", func: "myfunc" },

HTH
Rainer
0
 

Author Comment

by:jeffreyjseaman
ID: 39677872
Good suggestion; I went back and changed accordingly and it didn't work.
0
 
LVL 36

Accepted Solution

by:
Miguel Oz earned 500 total points
ID: 39686207
Actually your issue is how you define data, try this:
data: '{"SQLStr": "SELECT * FROM mytable", "Func": "myfunc"}',

Open in new window

Notice that I am defining data as string, another way of doing is to use JSON.stringify to convert your object to sting
data: JSON.stringify({ SQLStr: "SELECT * FROM mytable", func: "myfunc" }),

Open in new window

Note: Please add ASP.NET zone in your question next time so that you can have more experts helping you.
0
 

Author Closing Comment

by:jeffreyjseaman
ID: 39719863
Thank You .. That worked..
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
Viewers will learn the different options available in the Backstage view in Excel 2013.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question