开发者

JQuery ajax call to cross-domain webservice

I would like consume cross-domain web-service from client with jquery

function TestService() {
    $.ajax({
        url: "http://service.asmx/GetGeoCompletionList",
        data: { "prefixText":"eka", "count":"10", "contextKey":"Trace_0$Rus" },
        dataType: "jsonp",
        type: "GET",
        contentType: "application/json; charset=utf-8",
        success: function (data) {
            alert(data);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest.statusText);
        }
    });
}

At the error hander I have: textStatus=parseerror

XMLHttpRequest has status 200 and readyState 4

errorThrown is jQuery16103495572647140...78197139 was not called

I开发者_JAVA百科've spent on it for a lot of hours and couldn't make it work. Can u help me?

UPDATED

Thanks, I change to GET, and fix my data string.

Service returns valid JSON object. I can see it at firebug on other site, which consume this service. But that site is getting common json(since it has one domain).

So, if the web-service returns valid JSON(not jsonp), I can't use the same method with jsonp? What can I do for consiming json web-service from other domain?


That string you are passing and claiming is JSON isn't JSON.

Only " characters may be used to quote strings.

Also, you can't make a cross domain JSON-P POST request.


You cannot do cross-domain POST requests using JSONP. JSONP works by adding script tags to the page. script tags always fetch their source using GET HTTP requests. You won't get any data posted.


Summary of problems:

  1. Make sure you're using valid JSON as @Quentin mentioned.
  2. Make sure you're using GET requests, as @lonesomeday mentioned
  3. Make sure the response from the server is JSONP, as seen here
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜