Solved

JQuery Web Service call to C# Service

Posted on 2013-11-25
4
326 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
  • 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 35

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to hide the rows in Table when the value is empty ? 4 40
jQuery delay animation 3 30
Button to go back 3 25
jQuery slideToggle working incorrectly 3 24
Many companies are making the switch from Microsoft to Google Apps (https://www.google.com/work/apps/business/). Use this article to learn more about what Google Apps has to offer and to help if you’re planning on migrating to Google Apps. It is …
The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

803 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