[問題] 用ajax post 到php,但都失敗

看板Ajax作者 (阿呆)時間11年前 (2014/08/19 03:08), 11年前編輯推噓6(6016)
留言22則, 7人參與, 最新討論串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/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
textt.php的code呢?
08/19 10:48, 1F

08/19 10:54, , 2F
標題是POST,裡面的type是GET?
08/19 10:54, 2F

08/19 10:55, , 3F
php如果$_GET和$_POST寫反會有問題喔
08/19 10:55, 3F

08/19 11:21, , 4F
textt.php 裡面的code 是 <? echo "working"; ?>
08/19 11:21, 4F

08/19 11:22, , 5F
那個程式碼裡面的type 我原本是寫post
08/19 11:22, 5F

08/19 11:22, , 6F
要po 文忘記改回來了抱歉
08/19 11:22, 6F

08/19 11:23, , 7F
但還是無法傳輸成功
08/19 11:23, 7F

08/19 12:26, , 8F
你確定你的php有建立成功嗎?
08/19 12:26, 8F

08/19 12:27, , 9F
不然你把textt.php改成 textt.htm,然後再重試
08/19 12:27, 9F

08/19 13:57, , 10F
我跑了一下可以執行成功,先確定你到底能不能跑php吧。
08/19 13:57, 10F

08/19 14:51, , 11F
要不要看一下你直接打開textt.php會看到什麼...XD
08/19 14:51, 11F

08/19 16:30, , 12F
打開php 他顯示出working 那這樣是確定php 可以跑嗎?
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
軟體?notepad編輯php的標頭檔問題?
08/20 12:49, 18F

08/21 19:39, , 19F
是dreamweaver
08/21 19:39, 19F

08/21 19:40, , 20F
我把全部都上傳到空間 就沒問題了
08/21 19:40, 20F

08/21 23:01, , 21F
意思是說你本來是用 Dreamweaver 預覽嗎 0.0...
08/21 23:01, 21F

08/24 21:37, , 22F
別再用Dreamweaver...用sublime或npp吧
08/24 21:37, 22F
文章代碼(AID): #1Jyaz3F2 (Ajax)
文章代碼(AID): #1Jyaz3F2 (Ajax)