jQuery的呼叫到WebService的回报[否运输"错误 [英] jQuery Call to WebService returns "No Transport" error

查看:128
本文介绍了jQuery的呼叫到WebService的回报[否运输"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的Web服务;

I have the following web service;

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

这是标准的股票,没有改建为类装饰。

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

我有这个jQuery的方法;

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

这是一个POST操作,因为后来我需要将数据发布到它。

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

当我执行了jQuery,我收到了无传输错误返回。

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

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

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.

还有后面的HTML页面上没有code这是一个简单的网页,而不是C#项目或任何东西。

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?

推荐答案

如果您的jQuery的网页没有被从 HTTP下载://本地主机:54473 那么这个问题可能是因为你试图让跨域请求。

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.

更新1 看看这篇博客

更新2 如果这确实是问题(我怀疑它),你可能会想看看JSONP作为解决方案。这里有一些链接,可以帮助您入门:

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:

  • https://en.wikipedia.org/wiki/JSON
  • <一个href="http://remysharp.com/2007/10/08/what-is-jsonp/">http://remysharp.com/2007/10/08/what-is-jsonp/
  • <一个href="http://www.west-wind.com/weblog/posts/107136.aspx">http://www.west-wind.com/weblog/posts/107136.aspx
  • https://en.wikipedia.org/wiki/JSON
  • http://remysharp.com/2007/10/08/what-is-jsonp/
  • http://www.west-wind.com/weblog/posts/107136.aspx

这篇关于jQuery的呼叫到WebService的回报[否运输&QUOT;错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆