convert a async:false AJAX function into an $.Deferred one [duplicate]
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
javascript jquery ajax jquery-deferred
marked as duplicate by Quentin
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.
add a comment |
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
javascript jquery ajax jquery-deferred
marked as duplicate by Quentin
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
add a comment |
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
javascript jquery ajax jquery-deferred
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
javascript jquery ajax jquery-deferred
asked Nov 19 '18 at 13:20
mikexmagicmikexmagic
235
235
marked as duplicate by Quentin
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
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
$.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) );
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
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$.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) );
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
add a comment |
$.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) );
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
add a comment |
$.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) );
$.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) );
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
add a comment |
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
add a comment |
Maybe it can help stackoverflow.com/questions/4869609/….
– Nitin Kumar
Nov 19 '18 at 13:24