sanjeev40084
sanjeev40084

Reputation: 9617

Error while passing multiple parameters on Jquery ajax call?

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?

Upvotes: 3

Views: 458

Answers (1)

Kevin B
Kevin B

Reputation: 95020

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!");
        }
    });
}

Upvotes: 2

Related Questions