I have this jquery function and it fails after the form submission and never completes the second AJAX call. I'm not sure what I'm doing wrong or how I could write it differently to ensure that this does not happen. Other similar functions fail sporadically. In other words sometimes the second AJAX call is completed and sometimes it is not. I'm still learning, so please be patient with me.
$(document).ready(function(){
//Add the new player information through the Add Player button
$("#newPlayer_btn").click(function(){
var pn = $("#playerName").val();
var cn = $("#charName").val();
var cc = $("#charClass").val();
var cr = $("#charRace").val();
var cl = $("#charLevel").val();
var dataString = 'playerName='+ pn + '&charName='+ cn + '&charClass='+ cc + '&charRace='+ cr + '&charLvl=' + cl;
// AJAX Code To Submit Form.
$.ajax({
type: "POST",
url: "new_player.php",
data: dataString,
cache: false
});
//Reset the form after submission
$("#newplayerform")[0].reset();
//Add the player to the navigation menu.
$.ajax({
type: "POST",
url: "player_tab.php",
cache: false,
success: function(postresult){
$("#playernav").html(postresult);
}
});
return false;
});
});
One thing to note is that I have multiple subfunctions for other buttons under the main document.ready function. All of which have the same basic format. Am I misunderstanding something about how I should set this up? I can't figure out why some function calls work and others do not.