0

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.

Mr. Developer
  • 3,295
  • 7
  • 43
  • 110

1 Answers1

1

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

brk
  • 48,835
  • 10
  • 56
  • 78
  • Not an answer. More like a comment – Jai Jul 01 '16 at 14:16
  • @Jai _the error that comes back to me : CORS header " Access- Control-Allow -Origin " missing_. I think I have answered that and to get proper response it may need proper username, password and portfolioID which the user has not provided. Probably that is the reason of error in response. Otherwise I think i have addresses the issue of CORS – brk Jul 01 '16 at 14:19
  • request is redirected to error page, the request itself seems to work – Martin Ackermann Jul 01 '16 at 14:19
  • i can't use jsonp from directive api – Mr. Developer Jul 01 '16 at 14:28
  • @Mr.Developer sorry I dont understand what is directive api. `dataType` is just another configuration key of ajax. I think if you are using ajax you can also set the key. Check the jsfiddle – brk Jul 01 '16 at 14:30
  • i receive this error: SyntaxError: missing ; before statement "status":{ – Mr. Developer Jul 01 '16 at 14:30
  • supplier of my API does not allow to do jsonp calls but only as json datatype – Mr. Developer Jul 01 '16 at 14:31
  • @Mr.Developer probably that issue with the response but I guess you are no more facing CORS – brk Jul 01 '16 at 14:31