我有以下网络服务;
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
Run Code Online (Sandbox Code Playgroud)
它是库存标准,没有对类装饰器进行任何改动.
我有这个jQuery方法;
var webMethod = "http://localhost:54473/Service1.asmx/HelloWorld";
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
data: "{}",
dataType: "json",
url: webMethod,
success: function(msg){ alert(msg.d); },
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(errorThrown);
}
});
Run Code Online (Sandbox Code Playgroud)
这是一个后期操作,因为稍后我需要将数据发布到它.
当我执行jQuery时,我得到一个"无传输"错误.
我还应该提到的一点是,jQuery存储在我的机器上的一个简单的HTML文件中,而WebService也在我的机器上运行.
HTML页面上没有代码,它只是一个网页,而不是ac #project或任何东西.
任何人都可以指出我在正确的方向吗?
我正在使用跨域请求$.ajax.它适用于Firefox和Chrome,但不会在IE 7或8上发出呼叫.任何人都可以告诉我以下内容有什么问题吗?
Allow-access-control-origin在我的网站上使用标题了.(没有这些,Chrome和Firefox没有成功请求.)$.ajax({
type: 'GET',
url: "http://anotherdomain.com/Service/GetControl?id=" + zoneID,
cache: false,
contentType: "application/x-www-form-urlencoded",
async: false,
beforeSend: function (request) {
//alert('before send');
//request.setRequestHeader("X-Requested-With", "XMLHttpRequest");
//request.setRequestHeader("X-PINGOTHER", "pingpong");
} ,
success: function (data, status) {
//alert("Data returned :" + data);
//alert("Status :" + status);
if (status == "success" && data != "")
$("#" + div.id).append(data);
else
$("#" + div.id).attr("style", "display:none;");
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
alert(errorThrown);
}
});
Run Code Online (Sandbox Code Playgroud)
我尝试了多个网站上的各种提示,但还没有运气.