Note:
Missing a comma between post" and async
:
method: "Post"
async: false
Please DON’T USE async: false
, this is obsolete and in the future browsers will remove this feature, this because the synchronized mode usually freezes the browser, different from asynchronous, as I explained in:
And as described in https://xhr.spec.whatwg.org/#Sync-Warning
Then change approach to use callbacks, to understand what callback is read this answer:
Then change setInterval to setTimeout, so it will only call the next one if the first one has been sent
function recarregar()
{
$.ajax({
url: "http://xxxxxxx/o/Ano/1235",
dataType: "text",
method: "POST"
}).done(function (jsonData) {
var teste = jsonData;
}).always(function () {
setTimeout(recarregar, 10000);
});
}
Now about why you’re returning undefined
must be due within the scope of the variables, to pass the access of the variable test you would have to either put it as global (in the scope of window.
) and still add some kind of refresh in the specific DOM you want to change with the value, or else change the approach totally.
If you learn to use callbacks well you will probably be able to adjust everything, if you can indicate where you want to put the value of teste
I can adjust the code and give you some suggestion.
You don’t need to use
async:false
, use done or fail as shown in documentation : http://api.jquery.com/jquery.ajax/– Gabriel Rodrigues