2013-03-06 45 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