Mr. Developer
Mr. Developer

Reputation: 3417

json called hindered by Access- Control-Allow -Origin

I should make a json call with javascript:

var arr = { username: "user@user.com", password : "mypassword" , portfolioID : "xxxxxxxxxxxxxxxxx" };
    $.ajax({
        url: 'https://siam.eseye.com/login',
        type: 'POST',
        data: JSON.stringify(arr),
        dataType: "json",
        contentType: 'application/json; charset=utf-8',
        async: false,
        success: function(msg) {
            alert(msg);
        }
    });

the error that comes back to me : CORS header " Access- Control-Allow -Origin " missing . Attention, before saying that it is a double question , read here , I searched online and I did :

  1. inserted header ( " Access- Control-Allow -Origin : * " ) ;

  2. Wamp > Apache > Apache Modules > headers_module enabled

  3. added the datatype

  4. dataType: json or jsonp the error remain

after all of this evidence , it will not work the same .

Is there anything else I forgot to try? with Postman the API work.

Thank you.

Upvotes: 0

Views: 81

Answers (1)

brk
brk

Reputation: 50346

You may need to use dataType: "jsonp" which is use for cross site scripting.Check here for more about jsonp

I created this JSFIDDLE. The request semms to be served but the response have error. You can validate it console in developer's tool

Upvotes: 1

Related Questions