There is a strange error in my jQuery script. If I comment alert(“wait”); the second alert doesn’t show, although with this line it shows up.
/char/lol returns an xml with data.
$("#chat_form").submit(function(){
alert("wait"); // without this alert the second alert doesn't
$.post("/chat/lol",
{ user: $("#f_user").val(),
msg: $("#f_msg").val()
},
function(data){
alert("Im in");
},
'xml');
});
Edit:
This way it also works. IMPORTANT: “done” appears first, after that appears “Im in”. It seems like ‘submit’ exits before ‘post’ finishes and than it kills ‘post’.
$.post("/chat/lol", {user: $("#f_user").val(), msg: $("#f_msg").val()}, function(data){
// pobranie nowych wiadomości z serwera
alert("Im in");
}, 'xml');
alert("done");
What am I doing
wrong?
Try this:
i.e. I suspect you didn’t have return false (or preventDefault) that could be one of the reasons your ajax submit worked not exactly you want it to.