Bienvenue, Invité
Nom d'utilisateur : Mot de passe : Se souvenir de moi

SUJET : Calling API with jQuery/Javascript Version 2.0

Calling API with jQuery/Javascript Version 2.0 il y a 1 an 1 mois #93984

  • FrAgFo0d
  • Portrait de FrAgFo0d
  • Hors ligne
  • Fresh Lemon
  • Messages : 17
  • Karma: 0
Has anyone here have any knowledge about using jQuery to connect to the API?
I am using Limesurvey version 2.00 and setup the JSON-RPC.

I did a test on the API with http://10.0.0.2/index.php/admin/remotecontrol/test
The response I get is: "Invalid user name or password"

That seems O.K. to me.

But I tried several things with jQuery using $.ajax() and $.post()
trying to use: get_session_key however the API is non responsive.

So can anyone help me on the way with a small example of how this should work?
L'administrateur a désactivé l'accès en écriture pour le public.

Calling API with jQuery/Javascript Version 2.0 il y a 1 an 1 mois #94002

  • FrAgFo0d
  • Portrait de FrAgFo0d
  • Hors ligne
  • Fresh Lemon
  • Messages : 17
  • Karma: 0
So here is some more info.
This doesn't work (yet).

I do get a success from jQuery, however there is no response what so ever from the API (in Firebug).
Which basically means that jQuery did load the page, but the page was blank.
var params = {
    "method": "get_session_key",
    "params": {
        "username" : "admin",
        "password" : "test"
    },
    id: 1,
    jsonrpc: "2.0"
};
 
 
$.ajax({
    url: "http://LimeSurvey/index.php/admin/remotecontrol",
    type: "POST",
    contentType: "application/json",
    data: JSON.stringify(params),
    error: function(data) {
        console.log('error');
        console.log(data);
    },
    success: function(data) {
        console.log('success');
        console.log(data);
    }
});
L'administrateur a désactivé l'accès en écriture pour le public.

Calling API with jQuery/Javascript Version 2.0 il y a 1 an 1 mois #94018

  • FrAgFo0d
  • Portrait de FrAgFo0d
  • Hors ligne
  • Fresh Lemon
  • Messages : 17
  • Karma: 0
OK So I am also checking it out in the Dutch forum.

Somehow I can send the data to the API, but there is just no response from the API.
I checked my HTML Request headers and my POST body in Firebug and get this:
Accept	*/*
Accept-Encoding	gzip, deflate
Accept-Language	en-US,en;q=0.5
Content-Length	83
Content-Type	application/json; charset=UTF-8
Host	10.0.0.2
Referer	http://10.0.0.2/www/
User-Agent	Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:19.0) Gecko/20100101 Firefox/19.0
X-Requested-With	XMLHttpRequest
 
 
POST body:
{"method":"get_session_key","params":{"username":"admin","password":"test"},"id":1}

This is my Response Header:
Cache-Control	no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection	Keep-Alive
Content-Encoding	gzip
Content-Length	20
Content-Type	text/html
Date	Tue, 19 Mar 2013 15:23:41 GMT
Expires	Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive	timeout=15, max=99
Pragma	no-cache
Server	Apache/2.2.16 (Debian)
Vary	Accept-Encoding
X-Powered-By	PHP/5.3.3-7+squeeze15

I do not get any response body.
Could anybody help me out with this?
L'administrateur a désactivé l'accès en écriture pour le public.
Modérateurs: ITEd
Temps de génération de la page : 0.124 secondes
Donation Image