...

View Full Version : Jquery Ajax setTimeout problem



attasz
08-02-2010, 11:43 AM
I work on a shoutbox script.I send the data with AJAX,it goes into the db,then if it's successful i call a second Ajax function,sending a variable to my PHP page,this way ordering a refresh.The problem is that the second call is too quick,so it won't display the last message.I want to delay the second Ajax,but i can't figure out how.I tried setTimeout,but i get the function undefined message,or my browser froses,i tried the delay() function but i don't know where should i take it,i always get error messages.
The relevant code is:


$(document).ready(function(){
$("#mybutton_2").click(function(){
$("#newtext").val("");
});

$("#mybutton").click(function(){
var newText = $("#newtext").val();
newText = jQuery.trim(newText);
if(newText.length >= 1)
{
$.ajax({
type:"POST",
url:"sendit.php",
cahe:false,
data:"text=" + newText,
success:function(html) {

$.ajax({
type:"POST",
url:"shouts.php",
cahe:false,
data:"res=ok",
success:function(){

}
})
}
});

}
});
}

skywalker2208
08-02-2010, 04:30 PM
Why not have the sendit.php return what shouts.php returns? What is the reasoning to make a second call to the server when sendit.php just inserts it into the database?

Fumigator
08-02-2010, 06:00 PM
In addition to Skywalker's good suggestion, I don't think this is spelled right:


cahe:false,

attasz
08-02-2010, 08:05 PM
Thank you Skywalker2208,you are perfectly right,i'll do that.
Thank you Fumigator for showing me the typo.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum