Allow cross domain requests?

Allow cross domain requests?

Postby jose-pr » Wed May 06, 2015 6:09 pm

I want to write a little html/javascript page to test/debug the various api calls made available through schedules direct, will it be possible to add cross-domain requests on the server that host the api?
http://enable-cors.org/server.html
jose-pr
 
Posts: 20
Joined: Sat Mar 21, 2015 1:40 pm

Re: Allow cross domain requests?

Postby rkulagow » Wed May 06, 2015 7:03 pm

There's already cross-domain support; another developer asked for something similar, so it's in there. Are there specific calls that you're making that aren't working?
rkulagow
SD Staff
 
Posts: 884
Joined: Tue Aug 14, 2007 3:15 pm

Re: Allow cross domain requests?

Postby jose-pr » Wed May 06, 2015 7:55 pm

I tried to get a token and got an error
XMLHttpRequest cannot load https://json.schedulesdirect.org/20141201/token. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

This is the script that i was testing
Code: Select all
<script>
var token;
var lineups;
var sdApi = "https://json.schedulesdirect.org/20141201/";
function getToken(user,pass){
   return $.ajax({
      method: "POST",
      url: sdApi+"token",
      data: '{"username":"'+user+'","password":"'+pass+'"}',      
      success: function(json){token = json.token;},
      dataType: "json",
   });      
 }
 function setToken(){   
   var tokenDone = getToken($('#user').val(),$('#pass').val());   
}
$(document).ready(function() {
   $("#getToken").bind("click", function() { console.log( "CLICKED" );setToken();});
});
</script>
jose-pr
 
Posts: 20
Joined: Sat Mar 21, 2015 1:40 pm

Re: Allow cross domain requests?

Postby rkulagow » Wed May 06, 2015 10:14 pm

Let me take a look in the morning and I will let you know.
rkulagow
SD Staff
 
Posts: 884
Joined: Tue Aug 14, 2007 3:15 pm

Re: Allow cross domain requests?

Postby Classified » Mon Jan 02, 2017 7:55 am

I'm having the same exact issue with CORS. There are no
Code: Select all
Access-Control-Allow-*
headers in the response from the server at all. I don't know if I'm doing something wrong or is that a common issue? My request is plain POST with body and without any additional headers.

The code for that is (it's Angular 2 code so it will be hard to run, but I also did try using AJAX for that and it didn't work either):
Code: Select all
        let headers = new Headers({'Content-Type': null});
        let options = new RequestOptions({ headers: headers });
        const body = {"username":"<login>", "password":"<password>"};

        this.http
            .post(Configuration.SCHEDULE_URL + 'token', JSON.stringify(body), options)
            .map(res => res.json())
            .subscribe(token => console.log('token: ', token));


The error from Chrome is:
XMLHttpRequest cannot load https://json.schedulesdirect.org/20141201/token. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3001' is therefore not allowed access.
Classified
 
Posts: 1
Joined: Mon Jan 02, 2017 6:47 am


Return to Developer

Who is online

Users browsing this forum: No registered users and 1 guest