我有以下web服务;

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

这是现货标准,不会对班级装潢人员做任何改动.

I have this jQuery method;

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);
          }
});

It's a post action because later on I need to post data to it.

当我执行jQuery时,我得到一个返回的"No Transport"错误.

我还应该提到的一件事是,jQuery存储在我的机器上的一个简单HTML文件中,并且WebService也在我的机器上运行.

There is no code behind on the HTML page it's simply a web page and not a c# project or anything.

谁能给我指一下正确的方向吗?

推荐答案

如果您的jQuery页面没有从http://localhost:54473加载,那么这个问题可能是因为您试图提出跨域请求.

Update 1

Update 2个 如果这确实是问题所在(我怀疑是这样),您可能希望判断一下JSONP作为解决方案.以下几个链接可能会帮助您入门:

Jquery相关问答推荐

try 使用jQuery AJAX将参数传递给http Post方法时出现未知错误

使用 Ajax 列出数据(仅显示最后的数据)

如何在光滑的轮播上添加进度条

如果链接包含多个关键字,jQuery 将 HTML 添加到链接

更改高亮 colored颜色

当输入值以编程方式更改时触发更改事件?

在 CSS3 或 jQuery 中将元素的宽度从 0% 设置为 100% 动画,它和它的包装器只需要它们需要的宽度,没有预先设置的宽度

jQuery获取表单字段值

确定 JavaScript 值是否为整数?

如何在 JQuery DataTable 中默认显示所有行

Zepto 和 jQuery 2 有什么区别?

使用 JavaScript 和 jQuery,跨浏览器处理按键事件 (F1-F12)

如何使所有浏览器都支持 ?有什么 Select 吗?

循环判断复选框并计算每个选中或未选中的复选框

jQuery:如何从 $.ajax.error 方法中获取 HTTP 状态代码?

如何使用 javascript (jquery) 将整数值添加到返回字符串的值中?

为什么要定义一个匿名函数并将 jQuery 作为参数传递给它?

使用 jquery 禁用文本框?

获取jQuery中下拉列表的值

textarea 的 val() 与 text()