Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error running simple test #6

Closed
abnerjacobsen opened this issue Jul 20, 2017 · 3 comments
Closed

Error running simple test #6

abnerjacobsen opened this issue Jul 20, 2017 · 3 comments

Comments

@abnerjacobsen
Copy link

First of all I am not a javascript programmer.

I'm trying to make a simple call to a remote API on one of my servers. The code is below:

<html>
<head>
    <script src="rest-client.js"></script>
    <script>
        window.onload = function () {
            var api = new RestClient('https://api.asscontal.d.datanuvem.com/1.0');
            api.on('request', function(xhr) {
                xhr.setRequestHeader('Authorization', 'someapikey');
            });
            api.res({sites: 'sites'});

            api.sites.get().then(function(k){alert(k)});
        }
    </script>
</head>
<body>
</body>
</html>

However, the browser reports the following errors:

XMLHttpRequest cannot load https://api.asscontal.d.datanuvem.com/1.0/sites. Response for preflight is invalid (redirect)
rest-client.js:167 XHR failed loading: GET "https://api.asscontal.d.datanuvem.com/1.0/sites".
_request @ rest-client.js:167
self.get @ rest-client.js:236
window.onload @ daspanel.html:12
daspanel.html:1 Uncaught (in promise) XMLHttpRequest {readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, onreadystatechange: function…}

The copy of res-client.js I'm using was obtained from this URL: https://raw.githubusercontent.com/Amareis/another-rest-client/master/rest-client.js

What am I doing wrong ?

Thank you.

@Amareis
Copy link
Owner

Amareis commented Jul 20, 2017 via email

@Amareis
Copy link
Owner

Amareis commented Jul 20, 2017

Thirdly, when I'm skipping warning, site redirect me to another site, and this is root of the evil, because XMLHTTPRequest cannot into redirects on another domains.

@abnerjacobsen
Copy link
Author

Thanks, helped a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants