我正在尝试提交表单并使用php进行处理。这里是我做的(它简化,但仍然没有工作...)无法使用Ajax提交表单
这里我的索引:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script>
$().ready(function(){
$("#addemail").click(function(){
var email=$("#email").val();
$.ajax({
type: "POST",
url: "addemail.php",
data: "email="+email,
success: function(){
console.log("success! ")
},
error: console.log("error!! ")
});
});
});
</script>
</head>
<body>
<div id="wrapper">
<h2>Mon form...</h2>
<form action="">
<table>
<tr><td><label>Email:</label></td>
<td><input type="text" id="email" name="email" /></td>
<td><input type="submit" id="addemail" value="Add" /></td>
</tr>
</table>
</form>
</div>
</body>
这是我的PHP文件:
<?php
$connection = mysql_connect('localhost', 'XXX', 'XXX');
$db= mysql_select_db('mydb', $connection);
$email= $_REQUEST["email"];
$query = "INSERT INTO users(email) VALUES ('$email')";
mysql_query($query);
>
我在做什么错误(可能不是PHP,因为如果我在我的表单中给它起作用, php not ajax ...) Thanx提前
定义'not working'。你有错误吗?控制台告诉你什么? – PeeHaa
您有一个SQL注入漏洞。 – SLaks
@PeeHaa:呃,是的,我只有'错误!!'登录控制台...我怎样才能更好地调试jQuery? – blop