Solved

JQuery Web Service call to C# Service

Posted on 2013-11-25
4
328 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

How our DevOps Teams Maximize Uptime

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

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Lazy load not working with masonry js 1 22
jQuery - Add confirm message to button? 2 20
Ahax pagination 9 33
Responsive Font Size 6 29
As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

830 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