2013-03-06 66 views
0

我有一個組合,只是顯示一些MySQL數據庫。我也有一個創建數據庫的表單。我想動態地刷新組合(如果可能的話)以顯示由表單創建的新數據庫。這裏是代碼的一個片段:更新組合值

$('#createSL').click(function(){ 
      var sendIt = $("#slName").val(); 
      $.ajax({ 
       type: "POST", 
       url: "createSL.php", 
       data: {slName : sendIt}, 
       error: function(e){ 
        alert("The PHP Call failed! hmmm"); 
        alert(e.status); 
       }, 
       success: function(response){ 
        alert(response); 
       } 


      }); 
      $("#selcombo").load("combo.php"); 
      $("#tools").hide().html(data).fadeIn('fast'); 
     }); 

Combo.php:

<?php 

echo '<select id="tunelist" name="tunelist" >'; 
$link = mysql_connect('localhost', 'setlist', 'music'); 
$query = mysql_query("SHOW DATABASES"); 
echo '<option>Select a Show</option>'; 
while ($row = mysql_fetch_assoc($query)) { 
    if ($row['Database'] == "information_schema"){} 
    elseif ($row['Database'] == "performance_schema"){} 
    elseif ($row['Database'] == "mysql"){} 
    else{ 
     echo '<option value="'.$row['Database'].'">'.$row['Database'].'</option>'; 
    } 
} 
echo '</Select>'; 



?> 

如何去清涼

<div id="tools"> 

    <P>Add a Set list:<br> 
     <LABEL for="labelName">Set List Name: </LABEL> 
       <INPUT type="text" name="slName" id="slName"><button id="createSL" value="Create Setlist">Create Set</button> 
     </P><br> 
    <P>Delete a Set list:<br> 
     <? include("remSLcombo.php"); ?> <button href="#" type="button" id="delSl">Delete Setlist</button> 
    </P> 
    <p>Check how to reload combos</p> 

</div><BR> 


    <? include("combo.php"); ?> 

被稱爲創建數據庫jQuery函數在使用上面的表單添加數據庫之後,組合中的值(由combo.php製作)?

任何幫助一如既往是非常感謝!

羅蘭

+0

什麼問題? – Sam 2013-03-06 14:42:08

+0

@Sam我剛剛編輯,包括問題。對不起,我感到困惑 – 2013-03-06 14:46:11

回答

0

你所要做的就是給回createSL.php新組合框的代碼並加載在那裏。

這是你的代碼

  success: function(response){ 
       alert(response); 
      } 

寫類似:

 success: function(response){ 
      $('#tunelist').html(response); 
     } 

凡響應類似於Combo.php

0

嘗試移動

$("#selcombo").load("combo.php"); 

到你的內部success功能:

success: function(response){ 
    alert(response); 
    if (response == true) // or something like this to ensure the success of the operation 
     $("#selcombo").load("combo.php"); 
} 
+0

我試過了。它似乎有一個影響,但實際上並沒有重新運行combo.php,因爲沒有顯示新的數據庫。 – 2013-03-06 14:52:44