【问题标题】:Ajax asmx page no errorAjax asmx页面没有错误
【发布时间】:2014-12-17 18:49:51
【问题描述】:

我正在尝试使用以下内容进行 ajax Web 服务调用:

JQuery:

window.setInterval(function () {

            var reponse = '';
            $.ajax({
                 type: "post",
                 url: "http://ws/page.asmx/Test",
                 contentType: "application/json; charset=utf-8",
                 data: "{}",
                 dataType: "json",                   
                 success: function (data) {

                 reponse = data.d;
                $("#timer").text(reponse);
                alert("updated");
             },

             error: function (xhr, textStatus, err) {
                 console.log("readyState: " + xhr.readyState);
                 console.log("responseText: " + xhr.responseText);
                 console.log("status: " + xhr.status);
                 console.log("text status: " + textStatus);
                 console.log("error: " + err);
                 console.log("******************************");

             }
         });
    }, 3000);//time in milliseconds 

C# 网络方法

[System.Web.Script.Services.ScriptService]

  [WebMethod]
  [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
  public string Test() {
       return "Hello World";
  }

我的 ajax 返回以下内容:

"******************************" 
"readyState: 0" 
"responseText: " 
"status: 0" 
"text status: "
"error: " 
"******************************"

如何确定问题所在?

【问题讨论】:

    标签: c# jquery ajax web-services asp.net-ajax


    【解决方案1】:

    看起来您正在调用的 url 不允许跨区域调用。 CORS 可能存在问题。 您可以轻松获取有关 CORS 的信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-27
      • 2012-08-22
      • 2014-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多