No puedo mostrar el resultado en mi html porque la solicitud permanece en el estado 1 y el texto de respuesta se muestra indefinido. Cuando accedo a la url, muestra el valor que quiero mostrar en mi html. ¿Por qué está pasando esto? Estoy usando django en el lado del servidor por cierto. Un poco nuevo en ajax pero no he podido encontrar una respuesta a este problema en otras preguntas ya resueltas.
Código que ejecuta la solicitud:
const getHighScore = (gameID, levelID) => { let ajaxPrueba = $.ajax({ url: `/get-data/${gameID}/${levelID}`, type: 'get', success: function(data) { return data; }, failure: function(data) { console.log('Got an error dude'); } }); return ajaxPrueba; }Los parámetros que paso son 1 para gameID y 1 para levelID La URL de la que estoy hablando
También esto es lo que devuelve la consola:
ajaxPrueba = $.ajax({ url: `/get-data/1/1`, type: 'get', success: function(data) { return data;… Object { readyState: 1, getResponseHeader: getResponseHeader(e), getAllResponseHeaders: getAllResponseHeaders(), setRequestHeader: setRequestHeader(e, t), overrideMimeType: overrideMimeType(e), statusCode: statusCode(e), abort: abort(e), state: state(), always: always(), catch: catch(e) , … } abort: function abort(e) always: function always() catch: function catch(e) done: function add() fail: function add() getAllResponseHeaders: function getAllResponseHeaders() getResponseHeader: function getResponseHeader(e) overrideMimeType: function overrideMimeType(e) pipe: function pipe() progress: function add() promise: function promise(e) readyState: 4 responseText: "22" setRequestHeader: function setRequestHeader(e, t) state: function state() status: 200 statusCode: function statusCode(e) statusText: "OK" then: function then(t, n, r) <prototype>: Object { … } ajaxPrueba.readyState 4