I'd suggest you use only promises or only success handlers, not a mixture of both and you will not create this type of confusion. For example, I'm not sure whether there is an internal specification in jQuery for whether callbacks or promises are executed first. In either case, you should not rely on timing between them.
Here's a method that only uses promises which will not have that problem.
$.get('/u2').done(function(ospuntosyou) {
var numerodepuntos = parseFloat($(ospuntosyou).find('#field_id-13 dd').text());
console.log('Esto: '+numerodepuntos)
});
Note - I declared numerodepuntos
inside the .done()
handler and this is important because of the uncertainty of the timing for when that variable is filled in from outside the .done()
handler, you should only use that result inside the .done()
handler or in a function that you call and pass the data to from there. If you're confused about that, then read this reference on returned data from ajax calls:
How do I return the response from an asynchronous call?
FYI, there is no reason to use $.when()
on a single promise. You can just use the methods on the promise returned by $.get()
directly and this avoids asking $.when()
to create yet another promise.