0

I'm using curl to get json data from nuxeo, this my curl function

curl -X POST -H "Content-Type:application/json+nxrequest" -d 
"{ params:
        {
            query:'SELECT * FROM Document'
        }
}" -u Administrator:Administrator http://localhost:8080/nuxeo/site/automation/Document.Query

this function run fine, but now (with ajax version) I have error http 500. this is the code of ajax version

function getData(){
        var uri = "http://localhost:8080/nuxeo/site/automation/Document.Query" ;
        var options = {  method : 'post', data : 'query=SELECT * FROM Document' };
        var myCall = new Ajax(uri,options);
        myCall.request();

   }
Allel
  • 109
  • 9

2 Answers2

0

data needs to be an object. though not sure in mootools 1.12 - which you appear to be using.

in theory:

new Ajax(uri, {
    method: 'post',
    data: {
        query: 'select * from Document'
    }
}).request();

http://jsfiddle.net/dimitar/z5QzL/

Dimitar Christoff
  • 26,147
  • 8
  • 50
  • 69
  • thank's for your help but it's not running, i have the same error, so in my curl post i have this params -> "{ params: { query:'SELECT * FROM Document' } }" how can I convert this post in ajax ?! :) – Allel Jul 06 '12 at 08:30
  • see the js fiddle? this will send that as `$_POST['query']` (or whatever lang construct you have that holds post / request data). – Dimitar Christoff Jul 06 '12 at 08:45
0

For Nuxeo to work, you need to make sure you these two things in your AJAX call (as you do in your your curl call).

  1. Set Content-Type:application/json+nxrequest as a header.
  2. Pass in full json as data {"params":{"query":"SELECT * from Document"}}

If you fail to do these things, you will get a 500 return.

Looking at the server log on Nuxeo (server.log) might help you decipher exactly what you are sending with AJAX and help with the debugging of your problem.

Starkey
  • 9,673
  • 6
  • 31
  • 51