2012-06-07 46 views
1

即時通訊只是想知道如何使用JavaScript(我認爲這將是JavaScript,但不知道),搜索行動的結果顯示在另一個div內,就像網站,如易趣,甚至堆棧溢出。繼承人顯示錶單結果內部不同的div

<div id="searchsign"> 
    <div style="width: 65%; float:left;height:100%;"> 
     <form id="searchdivebay" action="searchdivebay.php" method="get"> 
     <div class="searchbox"><input type="text" name="searchbox" id="searchboxinput"/></div> 
     <div class="searchbtn"><input type ="submit" name="searchbutton" value="Search DiveBay"/></div> 
     </form> 
    </div> 
    <div style="width: 35%; float:right;height:100%;"> 
     <ul class="signreg"> 
     <li><i>Existing user?</i> <a href="#">SIGN IN</a></li> 
     <li><i>or, New user? </i><a href="#">REGISTER</a></li> 
     </ul> 
    </div> 
</div> 

<div id="main"> 
    <div style="height:2px; background-color:blue; top: 0px;"></div> 
     <div id="showsearch"> 

     </div> 

,是的,基本上我想有searchdivebay.php形式作用的結果,我的HTML片段在代碼底部顯示「showsearch」 DIV中。該腳本的作品,我可以發佈的代碼,如果有必要。但到了這一點,什麼是JavaScript(如果有)具有此功能?

+1

只有當您使用AJAX訪問此PHP頁面時,纔會使用唯一的JavaScript。否則,您需要將標籤放入div中,檢查表單是否已提交,然後根據該結果呈現結果。既然你有一個基本的形式,我敢肯定你沒有使用AJAX – Ian

回答

0

它看起來像你將要使用一些JQuery的像下面(當然這需要你實際上包括jQuery庫):

function fetchData(){ 
    var url = 'searchdivebay.php'; 
    // The jQuery way to do an ajax request 
    $.ajax({    
    type: "GET", 
    url: url, 
    data: "", // Your parameters here. looks like you have none 
    success: function(html){ 
     // html contains the literal response from the server 
     $("#showsearch").html(html); 
    } 
    }); 
} 

希望這有助於!

0

最簡單的方法是使用內聯框架並將其作爲目標在from中引用。當然,如果需要,內聯框架可以包裝在div內。例如:

<form id="searchdivebay" action="searchdivebay.php" method="get" 
    target="results"> 
... 
</form> 
... 
<iframe name="results" width="500" height="200"> 
</iframe>