I'm quite confused as to why this is happening.
I can't seem to pass data successfully via $.ajax
, the URL gets all mangled up instead of the data being passed in a query string.
I've cleaned up the code for brevity, see below.
Webservice (using GET)
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public string TestMethod(string country, string city)
{
return country + city;
}
jQuery
$.ajax({
url: "Test.asmx/TestMethod",
type: "GET",
data: '{"country":"' + country + '","city":"' + city + '"}',
dataType: "json",
success: function(msg) {
alert(msg.d);
}
});
Resulting URL and Error (in Firebug)
http://example.com/Test.asmx/TestMethod?{%22country%22:%22NZ%22,%22city%22:%22AK%22}
System.InvalidOperationException: Missing parameter: country.