It's many a times now that I've been trying to send my form data through Ajax to my server script without making the page refresh (using the onSubmit event of form). It all works fine with all the browsers (Chrome, IE, etc.) but when it comes to Firefox, the processing just keeps going on. I mean, even if the data has been sent to server side (yes, at many a times, I've got the data at the server side but the client is still under processing), the client doesn't respond to the consecutive calls.
For Example, consider one of my example codes:
Here is the Javascript
function submitComment(id)
{
//id is the id of the postbox
var content=$("#"+id).val();
var xmlhttp;
if(window.XMLHttpRequest)
xmlhttp=new XMLHttpRequest();
else
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4 && xmlhttp.status==200)
{
//action taken in response to the script from server in response to this form submission, eg, enabling back the submit button
$('input[type="submit"]').removeAttr('disabled');
}
}
$('input[type="submit"]').attr('disabled','disabled');
xmlhttp.open("POST",host+"comment.php?mode=newpost",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("post="+content);
$('#status').html('Posting your comment. Please wait...');//shows this status as long as gets no response from server
return false;
}
And here is its HTML:
<form id='newpostform' method=post action='' onSubmit="return submitComment('post')" >
<textarea id='post' name='post'></textarea>
<input type=submit value=Post>
<span id='status' style='padding:10px; font-size:12px; color:black; font-family:cambria, segoe ui;'>
</span>
</form>
So, In all the browsers, other than Firefox, the submit button is disabled for a while until the script communicates the post to server and when the server responds back, submit button is activated back and the status is updated.
Problem arises exactly here in Firefox. The status bar never changes its status even if the data has been communicated to the server!