Good afternoon everyone! I need to pass data in XML and JSON formats to an API I'm developing. Every time I put the contentType: "application / json / xml; charset = utf-8" into 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 defined:
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');