Call a PageMethod w/ jQuery using GET
I can call call my ASP.Net page methods fine if I use POST but if I try GET it fails. Any ideas why?
开发者_JS百科var url = encodeURI(acx.opts.queryURL + "?t=" + acx.input.val());
acx.requestExe = $.ajax({ type: "GET",
url: url ,
//data: "{\"t\":\"" + acx.input.val() + "\"}", //Data To Send If POST
contentType: "application/json", //Of Request
dataType: "json", //Return Type Expected
cache: true,
success: function(d) { showQueryResults(acx,d); },
error: function(d)
{
var r = JSON.parse(d.responseText);
alert(r.Message);
}
});
Check your web.config system.web -> httpHandler
and make sure your handlers allow the GET verb.
Try to pass data
as an object instead:
acx.requestExe = $.ajax({
type: "GET",
url: acx.opts.queryURL,
data: {
t: acx.input.val()
},
contentType: "application/json",
dataType: "json",
cache: true,
success: function(d) {
showQueryResults(acx,d);
},
error: function(d) {
var r = JSON.parse(d.responseText);
alert(r.Message);
}
});
Try specifying option.data
:
acx.requestExe = $.ajax({
type: "GET",
url: encodeURI(acx.opts.queryURL),
data: "{\"t\":\"" + acx.input.val() + "\"}",
contentType: "application/json",
dataType: "json",
cache: true,
success: function(d) { showQueryResults(acx,d); },
error: function(d) {
var r = JSON.parse(d.responseText);
alert(r.Message);
}
});
Instead of manually building it in your querystring:
var url = encodeURI(acx.opts.queryURL + "?t=" + acx.input.val());
精彩评论