PDA

View Full Version : Resolved Ajax/jQuery Post Data not working ?



bennyy007
08-10-2009, 02:20 PM
Hello everyone,

I do apologize if this is in the wrong forum, however I've made a Ajax/jQuery script to post form data, but the issue is that it gets to the loading message "Updating..." also I have "setTimeout" in place and when it reaches that timeout it still carrys on with the loading message, I'am using load() which is not the most constructive way as it doesn't handle errors but I aint here to discuss that.

So the problem is, that when it reaches "setTimeout" it hangs and carrys on displaying the loading message?

Here's my script:



<script type="text/javascript">
function procChgStMsg() {

$('#msgSt').fadeOut(); //hide the set status message
$('#editlink').fadeOut(); //hide edit link
$('#st_chg').fadeIn().css("display","").('slow');

}

//Now we do the changing

function chgStatusMsg() {

$('#st_chg').fadeOut().css("display","none"); //hide the edit form and set display to none
$('#myStatus').html('<img title="Processing..." src="ajax-loader.gif" /> Updating...'); //show a loading message
setTimeout(function(){ $('#myStatus').load(ChgStatus()); }, 2000);
}

function ChgStatus() {

var http = new XMLHttpRequest();

var stmsg = document.getElementById('st_msg').value;
var user = "<?php echo $session->userinfo['username']; ?>";

var url = "send.php";
var params = "mood=" + escape(stmsg) + "&username=" + escape(user);
http.open("POST", url, true);

//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");

http.onreadystatechange = function() {
if(http.readyState == 4 && http.status == 200) {
$('#myStatus').fadeOut();
$('#msgSt').fadeIn().html(http.responseText);
$('#editlink').fadeIn();
}

}
http.send(params);
}
//end
</script>


I must add that the reason for different functions is because, there's a div with text, which is then faded out using "fadeOut();" and then the edit form is faded in using "fadeIn();" which resides where the text was first before the user-end clicked on the edit link.

But as I said before it will not get to ChgStatus(), it will just hang on setTimeout();

Hopefully someone can help me solve this, or even point me in the right direction any help is muchly appreciated.

Thanks in advance!!!

EDIT: Solved this :D