jaredlee.exe
jaredlee.exe

Reputation: 81

Ember.js 2 Calls to .net API

I am building a SPA ember.js app that will hit a .net API via an ajax call.

ember.js

getData: function(){
  $.ajax({
    type: "POST",
    url: "http://localhost:9001/controller",
    dataType : "json",
    headers: "Access-Control-Allow-Origin",
    contentType: 'application/json; charset=utf-8',
    success : function(data) {
        return data;
    },
    error:function(data){
      alert('test' + data);
    }
  })
}

It returns an error message : SyntaxError: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': 'function () { return _emberRuntimeSystemString.fmt(this, arguments); }' is not a valid HTTP header field value.

I have been hammering away at this issue for a few hours now and I just can't seem to get around it. Also very new to ember.js.

If anyone has a better idea of whats going on...

Upvotes: 0

Views: 149

Answers (1)

Pavdro
Pavdro

Reputation: 427

Well, the problem is in your headers. You are not giving "Access-Control-Allow-Origin" a value. So you want something like

headers: {"Access-Control-Allow-Origin": 'value' }

Also, I don't think that particular header is used that way? I believe it's a header that the server sends. Check this post out - How does Access-Control-Allow-Origin header work?

Pav

Upvotes: 1

Related Questions