从数据库查询中回应多个iframe中的数据

问题描述:

我在一个页面中有6个iframe。数据库查询用一些数据行填充第一个iframe。当我从这个结果中选择任意一行(基于唯一键)时,我会对数据库运行另一个查询以获取有关该行的更多信息。从数据库查询中回应多个iframe中的数据

现在,我想在其他5个iframe中显示该信息的不同相关部分。 all the 6 iframes我该怎么做?

使用的技术:HTML5/CSS/Javascript/php/SQL Server。请参阅附加图像以获得更多清晰度。

+0

有太多可能的答案,或者对于这种格式太好的答案太长。请添加详细信息以缩小答案集或隔离可以用几个段落回答的问题。我建议你找一个开发论坛(也许[Quora](http://www.quora.com/Computer-Programming?))来解决一般问题。然后,当/如果您有特定的编码问题,请回到*,我们很乐意提供帮助。 –

+0

我想不使用iFrames,但带有AJAX请求的'JavaScript'会更容易。你可以使用它们还是仅限于'iframes'? – nicovank

+0

我可以使用AJAX。 – ajay

这是一个问题的答案原作者问他的问题的意见

你能提供这样的AJAX调用请的例子吗?

没有的jQuery(普通的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); 
+0

谢谢@nicovank。如果我理解代码,那么我将对数据库进行6次调用。那是对的吗?我只用一个电话就可以得到所有的信息。我的问题是如何将不同的信息片段定位到页面上的不同部分。对不起,如果我理解错了。 – ajay

+0

噢,在这种情况下,你的服务器响应了什么? JSON格式的数据?如果只是如何设置页面,使其看起来像你想要它会是CSS,而不是JavaScript。 – nicovank

+0

让我举个例子。如果你看看我之前附加的快照,让我们说,我在那里点击会话ID 4579。该点击将启动对数据库的查询以获取有关该会话的更多详细信息,并将发送11个列,这些列是我在此处附加的第2个快照中显示的。我拥有所有11个专栏,只是想在不同的框架或窗口中展示他们。 – ajay

感谢@nicovank的建议AJAX。这就是我所做的。在第一帧中选择一行时,将针对数据库运行单个查询以获取所有其他帧所需的信息。现在使用AJAX,我收集变量中的所有信息。然后,我决定需要在其他帧中显示哪些信息,并使用frame [i] .document.write(info_to_be_displayed_for_this_frame)来显示它。这是我错过的部分。现在都在工作。

感谢您的帮助。