我正在尝试将某些内容插入数据库。我将 php 调用到 $.ajax。textstatus 显示“Success”,但为什么表格仍然返回零结果?需要帮助真的很糟糕。谢谢。
HTML:
<div id="reg">
<form id="regform" name="regform" method="post">
Name: <input type="text" name="name"/>
<label id="name_error" for="name" class="error">Enter Your Complete Name.</label><br/>
<input type='submit' name="Submit Name" class="submit"/>
</form>
</div>
查询:
$(function() {
$('.error').hide();
$(".submit").click(function() {
$('.error').hide();
var name= $("input#name").val();
if(name==""){
$("label#name_error").show();
$("input#name").focus();
return false;
}
$.ajax({
type: "POST",
url: "http://localhost/folder1/folder2/reg.php";
sync: false,
data: {name:name},
success: function(data, textStatus){
//alert(data);
document.getElementById('reg').innerHTML = data + textStatus;
},
error: function(jqXHR){
alert(jqXHR.responseText);
}
});
return false;
});
});
PHP/reg.php
<?php
include "dbcon.php";
$name=$_POST['name'];
$query=mysql_query("INSERT INTO regtable ('name'), VALUES('$name')") or die();
if($query){
echo "1";
}else{
echo "2";
}
?>