Solved

JQuery Web Service call to C# Service

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
This collection of functions covers all the normal rounding methods of just about any numeric value.
Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

705 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now