AJAX Http POST:没有传输错误

AJAX Http POST : No transport error

本文关键字:传输错误 Http POST AJAX      更新时间:2023-10-22

这是我的网络方法:

[WebMethod]
    public string HelloWorld() {
        return "Hello World";
    }

这是html页面中的AJAX代码:

jQuery.support.cors = true;
                var btn_startOp = document.getElementById("startOpp");
                $.ajax({
                    type: "POST",
                    contentType: "application/xml; charset=utf-8",
                    data: "{}",  
                    dataType: "xml",
                    url: "http://localhost:61457/WebSite1/Service.asmx/HelloWorld",
                    success: function(msg){ alert(msg.d); },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alert(errorThrown);
                          }
                });

这给了我一个错误:开,

  • IE浏览器:无传输
  • Mozilla:未知

在浏览器上测试时,Web服务运行良好。

更新:这是Html:中head标签中的行

<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>

有人能帮我吗?这是我的第一个代码。我搜索了很多,对我来说仍然是个谜…:):(

更改为:

$.ajax({
  type: "GET",
  url: "/WebSite1/Service.asmx/HelloWorld",
  dataType:"json",
  success: function(msg) {
    alert(msg);
  },
  error: function(XMLHttpRequest, textStatus, errorThrown) {
    alert(errorThrown);
  }
});

  1. 您正在从Web方法返回一个字符串值,因此不需要dataType:"xml"
  2. 在浏览器上测试时,Web服务运行良好,这意味着您需要有一个GET请求