2016-11-09 105 views
0

我在一個頁面中有6個iframe。數據庫查詢用一些數據行填充第一個iframe。當我從這個結果中選擇任意一行(基於唯一鍵)時,我會對數據庫運行另一個查詢以獲取有關該行的更多信息。從數據庫查詢中迴應多個iframe中的數據

現在,我想在其他5個iframe中顯示該信息的不同相關部分。 all the 6 iframes我該怎麼做?

使用的技術:HTML5/CSS/Javascript/php/SQL Server。請參閱附加圖像以獲得更多清晰度。

+0

有太多可能的答案,或者對於這種格式太好的答案太長。請添加詳細信息以縮小答案集或隔離可以用幾個段落回答的問題。我建議你找一個開發論壇(也許[Quora](http://www.quora.com/Computer-Programming?))來解決一般問題。然後,當/如果您有特定的編碼問題,請回到StackOverflow,我們很樂意提供幫助。 –

+0

我想不使用iFrames,但帶有AJAX請求的'JavaScript'會更容易。你可以使用它們還是僅限於'iframes'? – nicovank

+0

我可以使用AJAX。 – ajay

回答

0

這是一個問題的答案原作者問他的問題的意見

你能提供這樣的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

0

感謝@nicovank的建議AJAX。這就是我所做的。在第一幀中選擇一行時,將針對數據庫運行單個查詢以獲取所有其他幀所需的信息。現在使用AJAX,我收集變量中的所有信息。然後,我決定需要在其他幀中顯示哪些信息,並使用frame [i] .document.write(info_to_be_displayed_for_this_frame)來顯示它。這是我錯過的部分。現在都在工作。

感謝您的幫助。