Jquery ajax post says xxx is not allowed Access-Control-Allow-Origin

I tried to call the eBay FindProducts API using AJAX ( postrequest), but got stuck with the following error:

XMLHttpRequest cannot load http://open.api.ebay.com/shopping?callname=FindProducts . The origin of http://localhost.com/test.php is not allowed by Access-Control-Allow-Origin.

My code is:

$.ajax
({
    type: "POST",
    url: 'http://open.api.ebay.com/shopping?callname=FindProducts',
    dataType: ($.browser.msie) ? "text" : "xml",
    contentType: 'application/x-javascript',
    crossDomain : true,
    data: {
        'X-EBAY-API-APP-ID' : 'ebayAppId', 
        'X-EBAY-API-VERSION': '771', 
        'X-EBAY-API-SITEID': '0', 
        'X-EBAY-API-REQUEST-ENCODING': 'NV', 
        'X-EBAY-API-RESPONSE-ENCODING': 'json',
        'QueryKeywords' : '753759971632',
        'MaxEntries' : '3'
    },
    success: function (result) {
        alert('success');
        alert(result);
    },
    error: function (data) {
        alert((data));
    }
})

How can I get through this error.

I tried to install dataType : jsonp(I know that XML is being extracted, but to work around the error I installed it in jsonP). It works, but jQuery was unable to parse the XML, as the json response was expected.

+3
source share
3 answers

&responseencoding=JSON URL-, JSON docs

UPDATE . , dataType:'jsonp' jsonp:'callbackname'. jQuery callback, eBay , callbackname. , . , , URL, . , .

+8

jQuery.ajax(), jsonp - .

, : jQuery 1.5 jQuery , Content-Type, , . , , XML, "text xml" dataType. JSONP, jQuery XML: "jsonp text xml". , "jsonp xml", jsonp xml , , jsonp , xml.

, , , dataType :

dataType: ($.browser.msie) ? "jsonp text xml" : "xml",

&responseencoding=JSON URL, .

0

, , , , .

dataType: 'jsonp' jsonp: 'callbackname'. jQuery , eBay , "callbackname". XML - CRO eBay ( .)

- , , JSON.Stringify().

, -!

Cheers,

0

All Articles