3

I am implementing .net webservice (asmx) using JSONP using this tutorial.

When I call my webservice, with a single parameter it works. However, when I try to call with mulitple parameters i keep getting Network 500 error. I tried to use "data: JSON.stringify({ jewellerId: filter, locale: 'en-US' })," as described in this stackoverflow question: Pass Multiple Parameters to jQuery ajax call. However it doesn't work.

Hers is my script:

function getData() 
{
    var key = "123";
    var code = "12458";
    jQuery.ajax({ url: http://service.com/test.asmx,
        data: JSON.stringify({ Key: key, Code: code }),
        dataType: "jsonp",
        success: function(json) 
        {
            alert(json.d);
        },
        error: function() {
            alert("Hit error fn!");
        }
    });
}

So, when i changed the webservice to take only one parameter, i changed the data to be like: data: {Key: JSON.stringify("123") } it worked.

Any suggestions how i can fix this?

Community
  • 1
  • 1
sanjeev40084
  • 9,227
  • 18
  • 67
  • 99
  • Adding content type made it work. http://stackoverflow.com/questions/8884928/cross-domain-call-with-jquery-jsonp-to-asp-net-web-service – sanjeev40084 Oct 22 '12 at 21:44

1 Answers1

2

Don't stringify the data if you are sending it as GET (which is the case for jsonp requests)

function getData() {
    var key = "123";
    var code = "12458";
    jQuery.ajax({ url: http://service.com/test.asmx,
        data: { Key: key, Code: code },
        dataType: "jsonp",
        success: function(json) {
            alert(json.d);
        },
        error: function() {
            alert("Hit error fn!");
        }
    });
}
Kevin B
  • 94,570
  • 16
  • 163
  • 180