JQuery submit form and output response or error message
- by sergdev
I want to submit form and show message about result.
update_records initializes alert_message to error message.
If success I expect that its value is changed.
Than update_records outputs message.
But the function always alerts "Error submitting form".
What is wrong with this?
The code follows:
function update_records(form_name) {
var options = {
async: false,
alert_message: "Error submitting form",
success: function(message) {
this.alert_message = message;
}
};
$('#' + form_name).ajaxSubmit(options);
alert(options.alert_message);
}
I am newbie in Javascript/JSon/Jquery and I suspect that I misunderstand some basics of mentioned technologies.
UPDATE:
I specified "async:false" to make execution synchronous (Is it correct?)
I also tried to insert delay between following two lines:
$('#' + form_name).ajaxSubmit(options);
pausecomp(1000); // inserted pause
alert(options.alert_message);
It also does not resolve the issue
Function fo pousecomp follows:
function pausecomp(millis)
{
var date = new Date();
var curDate = null;
do { curDate = new Date(); }
while(curDate-date < millis);
}