Skip to content
This repository has been archived by the owner on Oct 23, 2019. It is now read-only.

Jquery ajax client not working #36

Open
jeangui opened this issue May 26, 2014 · 3 comments
Open

Jquery ajax client not working #36

jeangui opened this issue May 26, 2014 · 3 comments

Comments

@jeangui
Copy link

jeangui commented May 26, 2014

Hi,

First, thanks a lot for this usefull meteor package. I have been using it for some weeks up to now.
Currently I need to request the rest API with jquery ajax queries.

I have modified the collectionapi.js file in order to handler cross domain request like this :

CollectionAPI._requestListener.prototype._sendResponse = function(statusCode, body) {
  var self = this;
  self._response.statusCode = statusCode;
  self._response.setHeader('Content-Length', Buffer.byteLength(body, 'utf8'));
  self._response.setHeader('Content-Type', 'application/json');
  self._response.setHeader('Access-Control-Allow-Origin', '*');
  self._response.setHeader('Access-Control-Allow-Methods','POST, GET, OPTIONS');
  self._response.setHeader('Access-Control-Allow-Headers','X-Requested-With');
  self._response.write(body);
  self._response.end();
};

But still I don't manage to query the api with jquery ajax.

Here is the error I get in the chrome js console 👍

OPTIONS http://localhost:3000/collectionapi/players 501 (Not Implemented) jquery-2.1.1.min.js:4
k.cors.a.crossDomain.send jquery-2.1.1.min.js:4
n.extend.ajax jquery-2.1.1.min.js:4
(anonymous function) test.html:13
XMLHttpRequest cannot load http://localhost:3000/collectionapi/players. Invalid HTTP status code 501 test.html:1

What should I do ?

Thanks in advance for your help.

cheers,

@jeangui

@xumx
Copy link

xumx commented Jun 9, 2014

I have the same problem. curl works fine. but POST/DELETE/PUT requests gets a 501 (Not Implemented) Error code.

What should I do?

@jeangui
Copy link
Author

jeangui commented Jun 13, 2014

Hello xumx,
i have modified a little bit the code to make or work. I'll upload it to a gist asap.
Cheers
Jeangui

@jeangui
Copy link
Author

jeangui commented Jun 16, 2014

Hello,

Here is the code. not very secure code. But it does what I wanted.

https://gist.github.com/jeangui/83bc29d383d24dd73b46

cheers
Jeangui

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

No branches or pull requests

2 participants