当用户单击按钮(+)时,我希望在div中插入一个新字段。
textfield的代码是:
<?php
$sql = "SELECT nome, codigo FROM ref_bibliograficas";
$result = mysql_query($sql) or die (mysql_error());
echo ("<select class='autocomplete big' name='ref_bib_0' style='width:690px;' required>");
echo ("<option select='selected' value=''/>");
while($row = mysql_fetch_assoc($result)){
echo ("<option value=" . $row["codigo"] . ">" . $row["nome"] . "</option>");
echo ("</select>");
mysql_free_result($result);
?>
因此,我不知道如何使用AJAX插入字段。
我用jQuery把这个函数按一下!有人能帮我吗?
谢谢!
发布于 2013-09-25 19:33:42
您要寻找的是jQuery .load()
函数。http://api.jquery.com/load/
让您的php页面输出您想要添加到div中的所需的HTML,那么您的JavaScript代码应该如下所示:
$('#addButton').click(function(){ // Click event handler for the + button. Replace #addButton wit the actual id of your + button
$('#myDiv').load('yourphppage.php'); // This loads the output of your php page into your div. Replace #myDiv with the actual id of your div
});
如果要在div中添加一个新字段,则应执行以下操作:
$('#addButton').click(function(){
$.post('yourphppage.php', function(data) {
$('#myDiv').append(data);
});
});
发布于 2013-09-25 19:37:40
Ajax方法
$(document).ready(function(e)
{
$('#plus-button').click(function(e)
{
$.ajax(
{
url: "PHP-PAGE-PATH.php", // path to your PHP file
dataType:"html",
success: function(data)
{
// If you want to add the data at the bottom of the <div> use .append()
$('#load-into-div').append(data); // load-into-div is the ID of the DIV where you load the <select>
// Or if you want to add the data at the top of the div
$('#load-into-div').prepend(data); // Prepend will add the new data at the top of the selector
} // success
}); // ajax
}
});
https://stackoverflow.com/questions/19013547
复制相似问题