0
Good afternoon, you guys! I need to pass data in XML and JSON formats to an API I am developing. Every time I place contenttype: "application/json/xml; charset=utf-8" in my Ajax block, I get the following error
XMLHttpRequest cannot load http://www.meuservico.com.br/api. No 'Access-Control-Allow-Origin' header is present on the requested resource.
$(function() { $.ajax({ type: "post", contentType: "application/json; charset=utf-8", url: 'http://www.e-sms.com.br/api', data: { name: 'norm' }, dataType: "json", success: function(data){ console.log(data); }, error: function (request) { console.log(request); } }); });
On the server, I have the following Header set:
header('Access-Control-Allow-Origin: *'); header("Access-Control-Allow-Headers: Origin,X-Requested-With,Content-Type, Accept"); header('Access-Control-Allow-Methods: GET, POST, PUT');
This error only happens when you set the content type?
– Miguel
Yes, if I remove, everything works.
– willian rodrigues andrade
I believe you have more relevant information;
– willian rodrigues andrade
The Datatype works cirretanebte.
– willian rodrigues andrade
After a search take a look here: http://api.jquery.com/jquery.ajax/ , see the content type part. And then vi http://stackoverflow.com/questions/8685678/cors-how-do-preflight-an-httprequest and here http://stackoverflow.com/questions/12320467/jquery-cors-content-type-options
– Miguel