meteor-collectionapi icon indicating copy to clipboard operation
meteor-collectionapi copied to clipboard

Jquery ajax client not working

Open jeangui opened this issue 10 years ago • 3 comments

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 :+1:

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

jeangui avatar May 26 '14 15:05 jeangui

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

What should I do?

xumx avatar Jun 09 '14 04:06 xumx

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 avatar Jun 13 '14 22:06 jeangui

Hello,

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

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

cheers Jeangui

jeangui avatar Jun 16 '14 12:06 jeangui