I have the following web service;

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

It's stock standard with no alterations to the class decorators.

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.

When I execute the jQuery I get a "No transport" error returned.

One thing I should also mention is that the jQuery is stored in a simple HTML file on my machine and the WebService is running on my machine also.

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

Can anyone please point me in the right direction here?

推荐答案

If your jQuery page isn't being loaded from http://localhost:54473 then this issue is probably because you're trying to make cross-domain request.

Update 1 Take a look at this blog post.

Update 2 If this is indeed the problem (and I suspect it is), you might want to check out JSONP as a solution. Here are a few links that might help you get started:

Jquery相关问答推荐

提交表单时运行自定义验证脚本

我需要在上一个表格单元格中显示计算结果

用 jQuery/JavaScript 检测数字或字母?

如何确定 jQuery 中匹配元素的元素类型?

如何在 jQuery 中 Select 特定的表单元素?

使用 JQuery 清除下拉列表

具有动态大小图像的马赛克网格 gallery

使用 D3.js(IE、safari 和 chrome)创建 SVG 后,如何保存/导出 SVG 文件?

如何在 JavaScript 或 jQuery 中规范化 HTML?

blueimp 文件上传插件中的 maxFileSize 和 acceptFileTypes 不起作用.为什么?

使用 jQuery Select 焦点文本在 Safari 和 Chrome 中不起作用

如何使用 Javascript/jQuery 确定图像是否已加载?

点击时保持 Bootstrap 下拉菜单打开

为不同的 node 类型配置jstree右键上下文菜单

使用 JQuery 获取触发事件的元素的类

好处和.在本地托管 jQuery 的trap

是否可以在 beforeunload 弹出窗口中显示自定义消息?

如何在纯 JavaScript 中模拟鼠标悬停以激活 CSS:悬停?

表单 propType 失败:您在没有 `onChange` 处理程序的情况下向表单字段提供了 `value` props

D3 和​​ jQuery 有什么区别?