This may be a problem somewhere else in my code, but I hope there's a clue here.
I'm using a jQuery AJAX call to update my MySQL database, and then another one to read the database and update a table on my page. My problem is that I update the database correctly, but my second AJAX call (wrapped in a function) is returning the old data. But if I fire the function again, it works perfectly.
Here's the first AJAX call:
$.ajax ({
cache: false,
type: 'POST',
url: 'qry_creats_record.php',
data: {
equipID : $('#equip_id').val(),
dateSent : $('#txt_to_repair').val(),
organization : $('#organization').val(),
success: function() {
ServiceTable($('#equip_id').val()); <--CALLS SECOND FUNCTION
}
}
});
Works great, updates the database perfectly. Then I want to update the page with this function (called in the 'Success' part of my first call):
function ServiceTable(equipID) {
var serviceRecords = $.ajax ({
cache: false,
type: 'POST',
url: 'qry_show_repairs_table.php',
async: false,
data: { equip_id : equipID
},
success: function() {
return data;
}
}).responseText;
$('#serviceRecordsTable').html(serviceRecords);
}
The second function works great as well, updates the page element 'serviceRecordsTable' if I call it from a button. But when I call it from the 'Success' part of the first call, it returns the old, non-updated data. I put an 'alert' box in my second function to see what was going on, and it confirms that the function is really seeing the old, pre-updated data from my database. But if I activate the second function from a button on the page, the second function refreshes my page with the new data.
Really stuck. Any help is appreciated.
Try like this -
Return string "success" from 'qry_creats_record.php'.