这可能是一个问题其他地方在我的code,但我希望有一个线索在这里。
This may be a problem somewhere else in my code, but I hope there's a clue here.
我使用jQuery的AJAX调用来更新我的MySQL数据库,然后另一个来读取数据库,并在我的网页更新表。我的问题是我正确地更新数据库,但我的第二个AJAX调用(包裹在一个函数)将返回旧数据。但是,如果我再次触发功能,它完美的作品。
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.
这是第一个AJAX调用:
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);
}
第二个函数的伟大工程,以及,更新页面元素serviceRecordsTable如果我从一个按钮来调用它。但是,当我第一次调用的成功的一部分调用它,它返回旧的,未更新数据。我把一个警告框在我的第二个功能,看看发生了什么事情,并确认该功能真的是从我的数据库看到老,pre-更新的数据。但是,如果我激活从页面上的一个按钮第二功能,第二个函数刷新我的网页使用新数据。
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.
真的卡住。任何帮助是AP preciated。
Really stuck. Any help is appreciated.
试试这样的 -
$.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(result) {
if(result=='success') {
ServiceTable($('#equip_id').val()); <--CALLS SECOND FUNCTION
}
}
});
返回字符串从qry_creats_record.php的成功。
Return string "success" from 'qry_creats_record.php'.