How to use Ajax contenttype to transfer XML and JSON data between services?

Asked

Viewed 908 times

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?

  • Yes, if I remove, everything works.

  • I believe you have more relevant information;

  • The Datatype works cirretanebte.

  • 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

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.