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?

1

1 Answer 1

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!");
        }
    });
}
Sign up to request clarification or add additional context in comments.

1 Comment

Are you sure the server you are requesting from can accept a request like this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.