문제

Im trying to make requests to a remote Rest (put method) api

var xhReq = new XMLHttpRequest();
xhReq.open("PUT", "http://api-easybib.apigee.com/2.0/rest/cite", true);
xhReq.setRequestHeader('Content-Type', 'application/json');
var jsonString = "{...}";

xhReq.send(JSON.stringify(jsonString));

var serverResponse = xhReq.responseText;

it fails with

No 'Access-Control-Allow-Origin' header

although i succeeded to make call via rest client browser plugins.

What am i missing?

도움이 되었습니까?

해결책

Because cause security, all browser are not accept a ajax cross-origin request from your site.

In order to browser accept a ajax cross-origin request, server code must set header "Access-Control-Allow-Origin" to response to notify browser that it accept a ajax cross-origin request.

In a browser plugin (ex: chrome app), chrome allow developer config to send request cross-origin. So you can send cross-domain request in REST Client plugin. (http://developer.chrome.com/apps/app_external.html#manifest)

다른 팁

Add the Access-Control-Allow-Origin on your server or use JSONP (see What is JSONP all about?)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top