Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
514 views
in Technique[技术] by (71.8m points)

ajax - jQuery Call to WebService returns "No Transport" error

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?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Add this: jQuery.support.cors = true;

It enables cross-site scripting in jQuery (introduced after 1.4x, I believe).

We were using a really old version of jQuery (1.3.2) and swapped it out for 1.6.1. Everything was working, except .ajax() calls. Adding the above line fixed the problem.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...