我想使用包含表单的克隆 div 使用此代码将记录插入数据库
$(document).ready(function() {
$("#button").click(function() {
$("<div class='newclone' id='xxx'><article><form method='post' id='aj'><input type='checkbox'><label>Firstname</label><input type='text' value='' name='firstname'><label>Secondname</label><input type='text' value='' name='secondname'><label>City</label><input type='text' value='' name='city'><input type='hidden' value='4'></article><input type='submit' value='insert' class='one'><button class='two'>Delete</button><button class='three'>Cancel</button></form></div>").appendTo('.clone-container');
});
$('.one').click(function() {
$.ajax({
type: "POST",
url: "insert.php",
data: $("#aj").serialize(),
success: function() {
alert('Inserted!');
}
});
});
});
这是php文件
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("clone", $con);
$firstname=$_POST['firstname'];
$secondname=$_POST['secondname'];
$city=$_POST['city'];
mysql_query("INSERT INTO clone(firstname,secondname,city) VALUES ('$firstname','$secondname','$city')");
编辑
问题是似乎没有发布任何内容