My website always freze with async false. I need to wait confirmation for execute script.
$.ajax({
type: "POST",
url: url,
data: form.serialize(),
async: false,
success: function(data) {
var conf = data;
}
});
if(conf == "ok")
{
alert('ok');
}
What is the good model for use this with async true please? I have tested with return but not work.
Edit:
$(function(){
window.wheel = {
init: {},
wheelof: function() {
$.ajax({
type: "POST",
url: url,
data: form.serialize(),
async: true,
success: function(data) {
alert('ok');
}
});
}
}
window.wheel.init();
});
$.ajax({
type: "POST",
url: url,
data: form.serialize(),
async: true,
success: function(data) {
var conf = data;
check(conf);
}
});
Pass data values to separate function after success.
function check(conf){
if(conf == "ok")
{
alert('ok');
}
}
$.ajax({
type: "POST",
url: url,
data: form.serialize(),
async: true,
success: function(data) {
var conf = data;
if ( conf === "ok" ) {
alert( "ok" )
}
}
});
Old question but didn't see any good answer, so here is mine from my experience:
$.ajax({
type: 'post',
url: url,
data: form.serialize()
})
.done(function(data){
var conf = data;
check(conf);
});
function check(conf){
if(conf == "ok"){
alert('ok');
}
}
This way the user experience doesn't suffer from unresponsive webpage. Using asynnc: false
is not a good solution.