我对AJAX相当陌生,它从来没有真正解决过,但我最终想要解决它。这就是为什么我要求你们帮忙!多年来,在阅读了数百个答案之后,我终于明白了我无法解决的问题。Ajax和PHP提交
我有一个显示一个表单填写一个简单的jQuery UI弹出:
<form>
<div id="Dialog2">
<p>Nieuwe Klant</p>
<table width="100%" border="0">
<tr>
<th scope="row">Naam:</th>
<td><input name="nc_name" type="text" id="nc_name" tabindex="1" /></td>
</tr>
<tr>
<th scope="row">Type:</th>
<td><select name="nc_type" id="nc_type" tabindex="2">
<option>Bedrijf</option>
<option>Particulier</option>
</select></td>
</tr>
<tr>
<th scope="row">Adres:</th>
<td><input name="nc_adres" type="text" id="nc_adres" tabindex="3" /></td>
</tr>
<tr>
<th scope="row">Postcode:</th>
<td><input name="nc_zip" type="text" id="nc_zip" tabindex="4" /></td>
</tr>
<tr>
<th scope="row">Land:</th>
<td><input name="nc_country" type="text" id="nc_country" tabindex="5" /></td>
</tr>
<tr>
<th scope="row">Stad:</th>
<td><input name="nc_city" type="text" id="nc_city" tabindex="6" /></td>
</tr>
<tr>
<th scope="row">KVK Nummer:</th>
<td><input name="nc_kvk" type="text" id="nc_kvk" tabindex="8" /> <input name="kvkzoek" type="button" id="kvkzoek" tabindex="7" value="Zoek Automatisch" onclick="seeKVKnumber()" /></td>
</tr>
<tr>
<th scope="row"><div id="info" /></th>
<td><input name="submit_two" type="button" id="submit_two" tabindex="9" value="Klant Toevoegen" /></td>
</tr>
</table>
<p><br />
</p>
</div>
</form>
这是由下面这段脚本在同一页面的页眉处理:
$(document).ready(function(){
$("#submit_two").click(function(){
var name=$("#nc_name").val();
var type=$("#nc_type").val();
var adres=$("#nc_adres").val();
var zip=$("#nc_zip").val();
var country=$("#nc_country").val();
var city=$("#nc_city").val();
var kvk=$("#nc_kvk").val();
$.ajax({
type:"get",
url:"addcustomer.php",
data:"name="+name+"&type="+type+"&adres="+adres+"&zip="+zip+"&country="+country+"&city="+city+"&kvk="+kvk,
success:function(data){
$("#info").html(data);
}
});
});
});
我已经使用“POST”以及“GET”,但都不起作用。 处理该INSERT到我的数据库PHP页面看起来是这样的:
<?
include('../includes/dbconfig.php');
$name=$_GET["name"];
$type=$_GET["type"];
$adres=$_GET["adres"];
$zip=$_GET["zip"];
$city=$_GET["city"];
$kvk=$_GET["kvk"];
$country=$_GET["country"];
//Insert query
$query = mysqli_query($con,"insert into customers(name, address, zipcode, city, kvk, country) values ('$name','$type','$adres','$zip','$city','$kvk','$country')");
if($query){
echo "Your comment has been sent";
}
else{
echo "Error in sending your comment";
var_dump($_GET);
}
mysqli_close($con); // Connection Closed
?>
每次我填写表格,我得到了错误:“错误的发送您的评论。”
即使后续代码var_dump($ _ GET)显示正确的价值观:
array(7) { ["name"]=> string(5) "MrBla" ["type"]=> string(7) "Bedrijf" ["adres"]=> string(6) "Blabla" ["zip"]=> string(7) "aaaabla" ["country"]=> string(6) "blabla" ["city"]=> string(3) "bla" ["kvk"]=> string(3) "bla" }
但值只是不会出现在数据库中。 Mozilla的Firebug也不会显示任何错误或中断。
我希望你们中的任何一位能够帮助我避开这些问题?
预先感谢大家,并感谢大家多年来为他人提供的许多有用答案。
它与ajax调用无关,它的插入到查询中有一个错误,它的字段列表中缺少“type”字段。而且,如果您在进行测试时使用'mysqli_error'或'$ mysqli-> error'而不是自定义错误消息,那么它会更好,因此您可以看到返回的确切错误。 – Thanu 2014-11-05 11:47:20