geogebratube api javascript petición ajax

Alan shared this question 4 years ago
Answered

Estoy intentando utilizar el api de geogebratube para realizar búsquedas de materiales desde mi webpage, mediante javascript y petición ajax utilizando método post con objetos JSON pero obtengo error como respuesta.


Este es mi código

*******************

var request = { "request": {"-api": "1.0.0",

"task": {

"-type": "fetch",

"fields": {

"field": [

{ "-name": "url" },

{ "-name": "title" },

{ "-name": "author" },

{ "-name": "author_url" }

]

},

"filters" : {

"field": [

{ "-name":"search", "#text":"integral" },

{ "-name":"language", "#text":"en" }

]

},

"order": {

"-by": "timestamp",

"-type": "desc"

},

"limit": { "-num": "3" }

}

}

};

var contenttype = "application/json; charset=utf-8";


var ajax_object = {

url : 'http://www.geogebra.org/api/json.php',

complete : function(xhr,status){

console.log(xhr, status);

},

method : 'POST',

data: request

};


$.ajax(ajax_object);

**********************


En el api no especifica si hay alguna restricción para realizar consultas mediante ajax, agradesco su pronta respuesta

Comments (2)

photo
2

Hi,


please try

data: JSON.stringify(request)

instead of

data:request

to make sure it's serialized as JSON string, not URI encoded.


Also it's better to use https:// instead of http:// to make sure your code works over https too.


Cheers,

Zbynek

photo
1

thanks a lot.


it seems that this combination was not tested, i tested json.stringify without https and vice versa but not boths...

photo
© 2020 International GeoGebra Institute