我在一个页面中有6个iframe。数据库查询用一些数据行填充第一个iframe。当我从该结果中选择任何一行(基于唯一键)时,我将对数据库运行另一个查询以获取关于该行的更多信息。
现在,我想在其他5个框架中显示该信息的不同相关部分。所有的6帧我怎么做呢?
使用的技术:HTML5/CSS/Javascript/php/SQL Server。这是对原作者在其问题评论中所提问题的回答
你能提供一个这样的AJAX调用的例子吗?
不使用jQuery (Plain JavaScript)
function getData(url, callback) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
callback(this.responseText);
}
};
xhttp.open("GET", url, true);
xhttp.send();
}
function useData(data) {
// This is where you are going to use the data to display your page (tables, text, etc...)
// /!' `data` is still a string. If you're using JSON for example, don't forget to `JSON.parse()` before using the code.
console.log(data);
}
// and finally call the getData function with the url and the callback
getData("myData.php", useData);
使用jQuery: function getData(url, callback) {
$.ajax({
url: url,
method: "GET",
success: callback,
error: function(xhr, textStatus, errorThrown) {
alert("AJAX error: " + errorThrown);
}
});
}
function useData(data) {
// This is where you are going to use the data to display your page (tables, text, etc...)
// This time, jQuery will do an intelligent guess and automatically parse your data. So wether you're using XML, JSON, ..., it's going to get parsed.
console.log(data);
}
// and finally call the getData function with the url and the callback
getData("myData.php", useData);
感谢@nicovank建议使用AJAX。这就是我所做的。当在第一帧中选择一行时,将对数据库运行一个查询,以获取所有其他帧所需的信息。现在使用AJAX,我将所有这些信息收集到一个变量中。然后,我决定需要在其他帧中显示哪些信息,并使用frame[I].document.write(info_to_be_displayed_for_this_frame)来显示这些信息。这是我错过的部分。现在一切正常。
谢谢你的帮助。