単純なhtmlフォームとjqueryがあります。そして、jqueryのajax関数を実行したいのですが、常にエラー応答が返されます。
私のコードは
<html>
<head>
<script src="jquery-1.8.1.min.js" type="text/javascript"></script>
</head>
<body>
<form action="" method="post" id="messageForm">
<table border=1>
<tr><td>Name</td><td align=right><input type="text" name="from" /></td></tr>
<tr><td>Surname</td><td align=right><input type="text" name="to" /></td></tr>
<tr><td colspan=2>Message</td></tr>
<tr><td colspan=2><textarea name="message" rows=10 cols=50> </textarea></td></tr>
<tr><td colspan=2 align=right><input type="submit" value="Send" /></td></tr>
</table>
</form>
<span id="textres">
</span>
<script lang="javascript">
$("#messageForm").submit(function(event) {
$.ajax({
url: "ajax.php",
data: $("#messageForm").serialize(),
cache: false,
error: function(XMLHttpRequest, textStatus, errorThrown){
//console.log or alert error
alert("textStatus:"+textStatus+",errorThrown:"+errorThrown+",XMLHttpRequest:"+XMLHttpRequest);
},
success: function(html){
alert("Data Loaded: "+html);
}
});
});
</script>
</body>
</html>
そして、成功イベントを実行することはありません。私がグーグルchoromeコンソールを見るとき、エラーはありません、そして私がのコードをコピーするならば
$.ajax({
url: "ajax.php",
data: $("#messageForm").serialize(),
cache: false,
error: function(XMLHttpRequest, textStatus, errorThrown){
//console.log or alert error
alert("textStatus:"+textStatus+",errorThrown:"+errorThrown+",XMLHttpRequest:"+XMLHttpRequest);
},
success: function(html){
alert("Data Loaded: "+html);
}
});
コンソールに、それはうまく機能します。単純なjqueryajax関数を実行するにはどうすればよいですか?