Hi, I'm trying to run the following code. I can see the ajax request in the firebug console, and it returns just fine. But, it's not acting as it should. Could someone take a look at this code and let me know if I'm doing something stupid?
- ajax_response = $.post(
- '/index.php/quote/verify_form/',
- form_data
- );
if (ajax_response.responseText == 'OK')
{
return true;
}
else
{
alert (ajax_response.responseText);
return false;
}
Most of the time when I watch it in Firebug, it works correctly, but when I run it outside the debugger, it always returns false, and the alert is blank. I'm thinking that it doesn't wait for the return value when it's running at normal speed.
I've also tried this, but it didn't work either:
- var ajax_response = '';
- $.post(
'/index.php/quote/verify_form/' + fieldsetName,
form_data,
- function (response_data) {
- ajax_response = response_data;
- }
);
if (ajax_response == 'OK')
{
return true;
}
else
{
alert (ajax_response);
return false;
}
When I tried this code, it seemed to completely skip over the assignment to ajax_response inside the $.post() function.
I'm wondering if I have a fundamental misunderstanding of scope inside of javaScript.
Thanks for the help.