Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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?

share|improve this question
Can you get to your web service just using a browser? – Avitus Mar 9 '11 at 3:55
Sorry, I didn't notice that this is a different post (I edited this post, thinking it was my own), I must've clicked the hyperlink to this one in my own post. Really sorry to the post owner =\ – Erick Garcia Jul 26 '11 at 11:05

4 Answers

up vote 72 down vote accepted

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:

share|improve this answer
3  
Yeah, it probably has something to do with security. – Codeglot Mar 9 '11 at 3:57
3  
It doesn't have to be localhost:54473, it just has to be the same domain. – jcolebrand Mar 9 '11 at 3:59
4  
@drachenstern Hm, I've always thought (and seem to remember always reading) that the scheme, host and port needed to be same. This and this and this seem to support my way of thinking about what constitutes the same domain. – no.good.at.coding Mar 9 '11 at 4:04
@no.good.at.coding I was so not aware of that. Many thanks. – jcolebrand Mar 9 '11 at 4:09
@drachenstern Glad to be of help! All this web stuff is tricky - something new to learn everyday :) – no.good.at.coding Mar 9 '11 at 4:11
show 4 more comments

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.

share|improve this answer
A bit more info here: blueonionsoftware.com/… – Andrew Arnott Jun 22 '11 at 1:19
12  
this fix my problem, worked in chrome and firefox but not IE. added this to the top of my script and all was good – Peter Jul 8 '11 at 4:40
@SrBlanco This fix my probem too, Thanks for sharing this info. – Mvcdev Jul 11 '11 at 21:10
2  
Very good fix,I had the same problem on Internet Explorer 9 when I was requesting a kml file from the same domain using a relative path... mysteries of IE... – contam Oct 21 '11 at 7:46
thanks. yes my rest calls stopped after 1.5 jquery updates. this code fixed it. – ashraf Dec 17 '11 at 1:52
show 10 more comments
jQuery.support.cors = true;

This solved my pending issue.

share|improve this answer
How does this answer the question? – user647772 Oct 19 '12 at 12:55
1  
For supporting a question try providing comments below the question – Prasad Jadhav Oct 19 '12 at 12:56
1  
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. – user647772 Oct 19 '12 at 12:58
1  
Well, it worked for me – Eric Frick Jan 8 at 14:30

i solve it by using dataType='jsonp' at the place of dataType='json'

share|improve this answer
FYI, that really wouldn't work for the original poster's request since jsonp doesn't support the POST verb, only GET. – John Williams Dec 3 '12 at 18:13
ya u r right, i used it for get feeds of fbwall, google+ etc using ajax – Abhishek Dec 12 '12 at 11:25

protected by Community Dec 31 '12 at 16:17

This question is protected to prevent "thanks!", "me too!", or spam answers by new users. To answer it, you must have earned at least 10 reputation on this site.

Not the answer you're looking for? Browse other questions tagged or ask your own question.