I am trying to use the jQuery dialog beforeClose . I check if the user form data is formatted correctly, and if not, returning false in beforeClose so that the user can re-enter the information.
Dialog code calls the submituserupdateform function in beforeClose :
.dialog({beforeClose: function () { formresult=submituserupdateform($('#myaccountdialog').find('form')); if (formresult !="okay"){ return false; } }})
The submituserupdateform function checks if there was an error in the code:
function submituserupdateform($tgt){ var url='./includes/admin/user/myaccount.php'; $.ajax({ type: "POST", url: url, data: $tgt.serialize(), success: function(data){ $("#myaccountdialog").html(data); if ($('.error').length){ var myresult= "notokay"; } else { var myresult ="okay"; } }, dataType: "html" }); return myresult; }
I searched and found https://stackoverflow.com/questions/1632039/return-value-from-ajax-call , but I already set myresult inside my callback. I also tried ajaxComplete , ajaxSuccess , .done . According to the console, nothing I tried installs myresult ; I always get:
Uncaught ReferenceError: myresult is not defined
It should be a simple mistake, please help me if you see my mistake!
source share