开发者

jQuery ajax GET fails

I have the following jQuery ajax request in a .js file:

$.ajax({
  type: "GET",
  url: "Download.aspx/ZipCheck",
  contentType: "application/json; charset=utf-8",
  data: "{}",
  dataType: "json",
  success: AjaxSucceeded,
  error: AjaxFailed
});

function AjaxSucceeded(result) {
  alert(result.d);
}

function AjaxFailed(result) {
  alert(result.status + ' ' + result.statusText);
}

The request fails and an alert pops up that says "200 OK". However, if I change the ajax request type to "POST" then it works and I have an alert that pops up with the expected data being returned from Download.aspx/ZipCheck.

Why does the GET fail, and why does the POST succeed? My understanding must be flawed about the difference between the two, because I thought that a GET request still 开发者_开发百科would return something from the server.


WebMethods are by default restricted to POST, you need to explicitly enable the GET request, for example using UseHttpGet on the ScriptAttribute, like this:

[WebMethod, ScriptMethod(UseHttpGet=true)]
public thing ZipCheck() {
  //return object
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜