convert a async:false AJAX function into an $.Deferred one [duplicate]












0
















This question already has an answer here:




  • How do I return the response from an asynchronous call?

    33 answers




I'm struggling now two days trying to convert a simple AJAX function with async:false into a nice jQuery Deferred() one. Everything I tried to return the AJAX response wont work :-(



this is my old (short) version of code:



function uiText($textID) {
var text = $.ajax({
url: "uitext.php",
async: false,
success: function(response){}
};
return text.response;
}
console.log(uiText('foo')); //shows me the response from uitext.php


How I can do this with $.Deferred and/or $.when().done()



Thx Mike










share|improve this question













marked as duplicate by Quentin ajax
Users with the  ajax badge can single-handedly close ajax questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 '18 at 13:34


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
















  • Maybe it can help stackoverflow.com/questions/4869609/….

    – Nitin Kumar
    Nov 19 '18 at 13:24
















0
















This question already has an answer here:




  • How do I return the response from an asynchronous call?

    33 answers




I'm struggling now two days trying to convert a simple AJAX function with async:false into a nice jQuery Deferred() one. Everything I tried to return the AJAX response wont work :-(



this is my old (short) version of code:



function uiText($textID) {
var text = $.ajax({
url: "uitext.php",
async: false,
success: function(response){}
};
return text.response;
}
console.log(uiText('foo')); //shows me the response from uitext.php


How I can do this with $.Deferred and/or $.when().done()



Thx Mike










share|improve this question













marked as duplicate by Quentin ajax
Users with the  ajax badge can single-handedly close ajax questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 '18 at 13:34


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
















  • Maybe it can help stackoverflow.com/questions/4869609/….

    – Nitin Kumar
    Nov 19 '18 at 13:24














0












0








0









This question already has an answer here:




  • How do I return the response from an asynchronous call?

    33 answers




I'm struggling now two days trying to convert a simple AJAX function with async:false into a nice jQuery Deferred() one. Everything I tried to return the AJAX response wont work :-(



this is my old (short) version of code:



function uiText($textID) {
var text = $.ajax({
url: "uitext.php",
async: false,
success: function(response){}
};
return text.response;
}
console.log(uiText('foo')); //shows me the response from uitext.php


How I can do this with $.Deferred and/or $.when().done()



Thx Mike










share|improve this question















This question already has an answer here:




  • How do I return the response from an asynchronous call?

    33 answers




I'm struggling now two days trying to convert a simple AJAX function with async:false into a nice jQuery Deferred() one. Everything I tried to return the AJAX response wont work :-(



this is my old (short) version of code:



function uiText($textID) {
var text = $.ajax({
url: "uitext.php",
async: false,
success: function(response){}
};
return text.response;
}
console.log(uiText('foo')); //shows me the response from uitext.php


How I can do this with $.Deferred and/or $.when().done()



Thx Mike





This question already has an answer here:




  • How do I return the response from an asynchronous call?

    33 answers








javascript jquery ajax jquery-deferred






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 '18 at 13:20









mikexmagicmikexmagic

235




235




marked as duplicate by Quentin ajax
Users with the  ajax badge can single-handedly close ajax questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 '18 at 13:34


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Quentin ajax
Users with the  ajax badge can single-handedly close ajax questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 19 '18 at 13:34


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • Maybe it can help stackoverflow.com/questions/4869609/….

    – Nitin Kumar
    Nov 19 '18 at 13:24



















  • Maybe it can help stackoverflow.com/questions/4869609/….

    – Nitin Kumar
    Nov 19 '18 at 13:24

















Maybe it can help stackoverflow.com/questions/4869609/….

– Nitin Kumar
Nov 19 '18 at 13:24





Maybe it can help stackoverflow.com/questions/4869609/….

– Nitin Kumar
Nov 19 '18 at 13:24












1 Answer
1






active

oldest

votes


















0















$.Deferred and/or $.when().done()




Don't. That's obsolete. $.ajax returns a promise compatible object.



function uiText($textID) {
const request = $.ajax({
url: "uitext.php"
});
return request;
}

uiText('foo').then( response => console.log(response) );





share|improve this answer


























  • I read so much about using promise stuff and I use it already in other situations. But i this case, I need that uiText returns the ajax response... not the promise object. Is this possible?

    – mikexmagic
    Nov 19 '18 at 13:32











  • @mikexmagic — No. $.Deferred and $.when().done() are just ways to create promises.

    – Quentin
    Nov 19 '18 at 13:33




















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0















$.Deferred and/or $.when().done()




Don't. That's obsolete. $.ajax returns a promise compatible object.



function uiText($textID) {
const request = $.ajax({
url: "uitext.php"
});
return request;
}

uiText('foo').then( response => console.log(response) );





share|improve this answer


























  • I read so much about using promise stuff and I use it already in other situations. But i this case, I need that uiText returns the ajax response... not the promise object. Is this possible?

    – mikexmagic
    Nov 19 '18 at 13:32











  • @mikexmagic — No. $.Deferred and $.when().done() are just ways to create promises.

    – Quentin
    Nov 19 '18 at 13:33


















0















$.Deferred and/or $.when().done()




Don't. That's obsolete. $.ajax returns a promise compatible object.



function uiText($textID) {
const request = $.ajax({
url: "uitext.php"
});
return request;
}

uiText('foo').then( response => console.log(response) );





share|improve this answer


























  • I read so much about using promise stuff and I use it already in other situations. But i this case, I need that uiText returns the ajax response... not the promise object. Is this possible?

    – mikexmagic
    Nov 19 '18 at 13:32











  • @mikexmagic — No. $.Deferred and $.when().done() are just ways to create promises.

    – Quentin
    Nov 19 '18 at 13:33
















0












0








0








$.Deferred and/or $.when().done()




Don't. That's obsolete. $.ajax returns a promise compatible object.



function uiText($textID) {
const request = $.ajax({
url: "uitext.php"
});
return request;
}

uiText('foo').then( response => console.log(response) );





share|improve this answer
















$.Deferred and/or $.when().done()




Don't. That's obsolete. $.ajax returns a promise compatible object.



function uiText($textID) {
const request = $.ajax({
url: "uitext.php"
});
return request;
}

uiText('foo').then( response => console.log(response) );






share|improve this answer














share|improve this answer



share|improve this answer








answered Nov 19 '18 at 13:24


























community wiki





Quentin














  • I read so much about using promise stuff and I use it already in other situations. But i this case, I need that uiText returns the ajax response... not the promise object. Is this possible?

    – mikexmagic
    Nov 19 '18 at 13:32











  • @mikexmagic — No. $.Deferred and $.when().done() are just ways to create promises.

    – Quentin
    Nov 19 '18 at 13:33





















  • I read so much about using promise stuff and I use it already in other situations. But i this case, I need that uiText returns the ajax response... not the promise object. Is this possible?

    – mikexmagic
    Nov 19 '18 at 13:32











  • @mikexmagic — No. $.Deferred and $.when().done() are just ways to create promises.

    – Quentin
    Nov 19 '18 at 13:33



















I read so much about using promise stuff and I use it already in other situations. But i this case, I need that uiText returns the ajax response... not the promise object. Is this possible?

– mikexmagic
Nov 19 '18 at 13:32





I read so much about using promise stuff and I use it already in other situations. But i this case, I need that uiText returns the ajax response... not the promise object. Is this possible?

– mikexmagic
Nov 19 '18 at 13:32













@mikexmagic — No. $.Deferred and $.when().done() are just ways to create promises.

– Quentin
Nov 19 '18 at 13:33







@mikexmagic — No. $.Deferred and $.when().done() are just ways to create promises.

– Quentin
Nov 19 '18 at 13:33





Popular posts from this blog

Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

ComboBox Display Member on multiple fields

Is it possible to collect Nectar points via Trainline?