[問題] 用ajax post 到php,但都失敗
翻了很多文章,怎麼改都不對,想請各位大大看看到底我是哪裡寫錯了@@
執行都跳出失敗的對話框
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>無標題文件</title>
</head>
<body>
</body>
</html>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js
"></script>
<script type="text/javascript" src="http://simplesideias.com.br/media/ajax.js"
></script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>留言板兒兒兒</title>
</head>
<body>
<font size="+6" color="#00CCFF" ><b>ya快來留言</b></font><br><br>
<form method="post" id="message_form" >
<!-- 以下是user送出表單內容-->
your name:
<input type="text" name="username" id="username" size="20" maxlength="20">
<br><br>
<textarea name="message" id="message" style="height:120px;width:400px"></t
extarea><br><br>
<input type="button" name="submit" id="submit" value=" 留言 " onClick="Che
ckIt();" >
<!------------->
</form>
<div id="result" ></div>
<SCRIPT type="text/javascript">
function CheckIt(){
// 檢查是否有符合留言條件
var username = $('#username').val();
var message = $('#message').val();
if ( username.length > 10 ) {
alert("Username 不可以超過十個字!");
return false;
}
else if ( message.length > 20 ) {
alert("Message 不可以超過二十個字!");
return false;
}
else {
alert("傳訊息囉!");
GOmessage();
};
} ;
</script>
<script type="text/javascript">
function GOmessage(){
var username = $('#username').val();
var message = $('#message').val();
/*
$.post('/textt.php',{Pusername:username,P
age},
function(data)
{
alert("you success!!!!");
},"text"
);
alert( "good!!!!" );
*/
$.ajax({
url:"textt.php",
data:'message=message&username=username',
type : "GET",
dataType:'text',
timeout:1000,
error:function (data){
$("#result").html(data);
alert("失敗");
},
success:function(){
alert("成功");
}
});
};
</SCRIPT>
</body>
</html>
--
Sent from my Android
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 223.143.249.21
※ 文章網址: http://www.ptt.cc/bbs/Ajax/M.1408388931.A.3C2.html
※ 編輯: hao520wxj (223.143.249.21), 08/19/2014 03:09:39
※ 編輯: hao520wxj (223.143.249.21), 08/19/2014 03:11:15
推
08/19 10:48, , 1F
08/19 10:48, 1F
→
08/19 10:54, , 2F
08/19 10:54, 2F
→
08/19 10:55, , 3F
08/19 10:55, 3F
→
08/19 11:21, , 4F
08/19 11:21, 4F
→
08/19 11:22, , 5F
08/19 11:22, 5F
→
08/19 11:22, , 6F
08/19 11:22, 6F
→
08/19 11:23, , 7F
08/19 11:23, 7F
→
08/19 12:26, , 8F
08/19 12:26, 8F
→
08/19 12:27, , 9F
08/19 12:27, 9F
→
08/19 13:57, , 10F
08/19 13:57, 10F
推
08/19 14:51, , 11F
08/19 14:51, 11F
→
08/19 16:30, , 12F
08/19 16:30, 12F
→
08/19 16:30, , 13F
08/19 16:30, 13F
推
08/19 17:24, , 14F
08/19 17:24, 14F
→
08/20 00:39, , 15F
08/20 00:39, 15F
→
08/20 00:39, , 16F
08/20 00:39, 16F
推
08/20 11:28, , 17F
08/20 11:28, 17F
推
08/20 12:49, , 18F
08/20 12:49, 18F
→
08/21 19:39, , 19F
08/21 19:39, 19F
→
08/21 19:40, , 20F
08/21 19:40, 20F
推
08/21 23:01, , 21F
08/21 23:01, 21F
→
08/24 21:37, , 22F
08/24 21:37, 22F
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章
6
32