【问题标题】:Jquery ajax not hitting serverJquery ajax没有命中服务器
【发布时间】:2013-07-26 07:10:45
【问题描述】:

我当前的应用程序中有一个 htm 页面和一个 service.aspx 和 service.aspx.cs 文件。我正在使用.Net 4.0。在 service.aspx.cs 页面中,我有如下测试方法。

[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Xml)]
public static string test()
{
    return "AA";
}

在我的html页面中

 $.ajax({
    type: "GET",
    cache: false,
    url: "NextGenFormService.aspx/test",
    dataType: "xml",
    contentType: "text/html",
    success: AjaxSucceeded,
    error: AjaxFailed
});  //end of $.ajax;

如果我在我的服务器中保留一个断点,它就不会命中。 AjaxSucceeded 被 200 OK 调用,responseText 为空。

同样适用于内容类型:应用程序/json,数据类型:json。

我试图从服务器或测试方法发送的只是 html 和 JavaScript。

【问题讨论】:

  • 已在浏览器中检查了您的网址是否有效?
  • 尝试安装 Fiddler2 来监控您的请求。该请求说明了什么?
  • 提琴手响应为空。
  • 和跨域有关系吗?但为什么同样适用于 json 数据类型和内容类型。

标签: asp.net jquery get


【解决方案1】:

使用默认的contentType,因为您什么都不发送,更改为html 数据类型。

有时 asp.net 不喜欢缺少数据属性,即使是这样的空属性:

$.ajax({
    data:{},
    type: "GET",
    cache: false,
    url: "NextGenFormService.aspx/test",
    dataType: "html",
    contentType: "application/x-www-form-urlencoded;",
    success: AjaxSucceeded,
    error: AjaxFailed
});

【讨论】:

    猜你喜欢
    • 2015-03-27
    • 2014-04-09
    • 1970-01-01
    • 1970-01-01
    • 2021-09-21
    • 2012-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多