I\'m trying to call the webmethod fucntionality using AJAX but unable to get the appropriate results. I have googled my problem and found many solution but thos
In my case the problem was the "data" field (both cases, GET and POST). As a test, remove the "data" from the AJAX call and also remove the web method parameter, if it works, then the problem is the format of the "data" field:
$.ajax({
type: "GET",
url: pagePath,
contentType: "application/json; charset=utf-8",
dataType: "json",
...
[WebMethod]
[ScriptMethod(UseHttpGet = true)]
public string getUsername()
{
return "True";
}
Some examples:
data: JSON.stringify({ "parameter": variable }) WORKS
data: JSON.stringify({ parameter: variable }) WORKS
data: '{"parameter": "' + variable + '"}' WORKS
data: '{parameter: ' + variable + '}' don't works
data: JSON.stringify({ 'parameter': 'value' }) WORKS
data: '{"parameter":"value"}' WORKS
data: "{'parameter':'value'}" WORKS
data: '{parameter:value}' don't works
data: {parameter:value} don't works
data: {"parameter":"value"} don't works
data: {'parameter':'value'} don't works