JQuery submit form and output response or error message
Posted
by sergdev
on Stack Overflow
See other posts from Stack Overflow
or by sergdev
Published on 2010-05-19T20:41:45Z
Indexed on
2010/05/19
21:10 UTC
Read the original article
Hit count: 303
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);
}
© Stack Overflow or respective owner