jquery ajax post sagt, dass xxx von Access-Control-Allow-Origin nicht erlaubt ist
Ich habe versucht, die eBay FindProducts-API mit AJAX aufzurufen (post
Anfrage) steckte aber bei folgendem Fehler fest:
XMLHttpRequest kann nicht geladen werdenhttp://open.api.ebay.com/shopping?callname=FindProducts. Ursprunghttp://localhost.com/test.php wird von Access-Control-Allow-Origin nicht zugelassen.
Mein Code:
$.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));
}
})
Wie komme ich durch diesen Fehler.
Ich habe versucht, Einstellungen vorzunehmendataType : jsonp
(Ich weiß, dass XML abgerufen wird, aber um den Fehler zu umgehen, habe ich es auf jsonP gesetzt.) Es funktioniert, aber jQuery konnte das XML nicht analysieren, da die json-Antwort erwartet wurde.