ページを更新せずに送信したい単純なフォームを作成したので、jQueryを使用します。フォームを送信すると問題が発生しますが、process.phpはデータが変換されなかったことを報告し、process.phpは「投稿を受信していません」というメッセージを出力します。フォームファイルのコードは次のとおりです。
<!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 /フォームの何が問題になっているのか分かりますか?どんな提案も歓迎します、ありがとう