我已经构建了一个简单的表单,我想在不刷新页面的情况下发送,因此我使用jQuery。提交表单时出现问题,但process.php报告数据未转换,并且process.php输出消息“no post received”。 这里的表单文件的代码:PHP jQuery表单提交
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1255">
<title>Insert title here</title>
</head>
<script type="text/javascript">
$(function(){
$('#submit').click(function(){
var getField = $("#field").val();
$.ajax({
url: 'process.php' ,
type: 'POST',
data: 'data: ' + getField,
success: function(result){
$('#container').text('<p>' + result + '</p>')
}
});
return false;
});
});
</script>
<body>
<div id="container">
<form method="post" action="process.php">
<input name="field" id="field" type="text" />
<input type="submit" value="submit" id="submit" />
</form>
</div>
</body>
</html>
这里的process.php代码:
<?php
if($_POST){
echo $_POST['field'];
}
else
echo "no post received";
?>
你有什么想法,有什么错了jQuery /形式? 欢迎任何建议, 谢谢
实际上,我认为他需要提交实际的对象:data:{data:getField}, – FrankieTheKneeMan 2012-08-13 19:42:12
现在工作得很好,谢谢! – Itamar 2012-08-13 19:42:35