Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

JQuery Web Service call to C# Service

Posted on 2013-11-25
4
Medium Priority
?
336 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
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…
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…

721 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