[問題] 試著用ajax pose 資料到php

看板Web_Design作者 (阿呆)時間11年前 (2014/08/19 03:02), 11年前編輯推噓4(4013)
留言17則, 4人參與, 最新討論串1/1
不管怎麼該都是傳送錯誤,翻了很多文都沒有用,想請各位大大幫我看看是哪裡錯了!! <!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/Web_Design/M.1408388554.A.B9E.html ※ 編輯: hao520wxj (223.143.249.21), 08/19/2014 03:11:58

08/19 03:33, , 1F
success:function(data){alert(data);}
08/19 03:33, 1F

08/19 03:33, , 2F
看一下返回值是什麼
08/19 03:33, 2F

08/19 03:54, , 3F
我在success 上加 沒有對話框出現,在error 上加的話出
08/19 03:54, 3F

08/19 03:54, , 4F
現了[object object]
08/19 03:54, 4F

08/19 05:17, , 5F
有東西代表你有傳過去也有回來。請打開console直接看
08/19 05:17, 5F

08/19 05:17, , 6F
回來的是什麼東西。
08/19 05:17, 6F

08/19 13:15, , 7F
出現在 error 的話應該是沒有回來或連不上... @_@?
08/19 13:15, 7F

08/19 14:25, , 8F
原po要不要直接用瀏覽器打開textt.php看會出現什麼@@?
08/19 14:25, 8F

08/19 14:25, , 9F
例如可能發生 404 或 500 錯誤之類的...
08/19 14:25, 9F

08/19 16:32, , 10F
我的php裡面只有echo "working "~
08/19 16:32, 10F

08/19 16:32, , 11F
打開testt.php 會出現working
08/19 16:32, 11F

08/19 19:28, , 12F
你所謂的"錯誤",是說按下之後會彈出"失敗"對吧 @@
08/19 19:28, 12F

08/19 19:32, , 13F
textt.php 和你執行 AJAX 的頁面是在同個資料夾下嗎 @@
08/19 19:32, 13F

08/20 00:39, , 14F
08/20 00:39, 14F

08/20 00:40, , 15F
結果發現程式沒有問題
08/20 00:40, 15F

08/20 00:40, , 16F
似乎是因為軟體的關係
08/20 00:40, 16F

08/20 00:40, , 17F
謝謝各位大大的解~
08/20 00:40, 17F
文章代碼(AID): #1JyatAkU (Web_Design)