2

I have the following web service;

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

I am pointing to the latest jquery library.

 <script type="text/JavaScript" src="Scripts/jquery-1.6.4.js"></script>

I have this jQuery method;

$.ajax({
            type: "POST",
            url: "../Service/AFARService.asmx/HelloWorld",
            // this._baseURL + method,
            data: data,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: fnSuccess,
            error: fnError,
            crossDomain: true,
            dataFilter: function (data) {
                var response;

                if (typeof (JSON) !== "undefined" && typeof (JSON.parse) === "function")
                    response = JSON.parse(data);
                else
                    response = val("(" + data + ")");

                if (response.hasOwnProperty("d"))
                    return response.d;
                else
                    return response;
            }
        });

When I execute I get a "No transport" error returned. I added crossDomain: true still no success.

Thanks in advance BB

BumbleBee
  • 10,429
  • 20
  • 78
  • 123
  • The response from your server, `"Hello World"`, is not valid JSON! – Eric Oct 10 '11 at 21:41
  • What happens if you view `../Service/AFARService.asmx/HelloWorld` in the browser? – Eric Oct 10 '11 at 21:42
  • 1
    a similar question asked here maybe it'll help http://stackoverflow.com/questions/5241088/jquery-call-to-webservice-returns-no-transport-error/5241121#5241121 – Rafay Oct 10 '11 at 21:42
  • Useful? Error hauntingly similar: http://stackoverflow.com/questions/5241088/jquery-call-to-webservice-returns-no-transport-error – artlung Oct 10 '11 at 21:42

2 Answers2

2

to enable cross domain calls, you can try

jQuery.support.cors = true;

if this doesn't works you can go through(JSONP) :
http://www.west-wind.com/weblog/posts/2007/Jul/04/JSONP-for-crosssite-Callbacks
https://en.wikipedia.org/wiki/JSON
http://remysharp.com/2007/10/08/what-is-jsonp/

you can follow any of these

Krenair
  • 570
  • 5
  • 21
NG.
  • 5,695
  • 2
  • 19
  • 30
0

try using

 url: "AFARService.asmx/HelloWorld",



[WebMethod]
 [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public string HelloWorld()
{
    return "Hello World";
}
Webbies
  • 97
  • 3
  • 11