سؤال

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