Re: [問題] $.ajax可以使用get但是無法使用post

看板Ajax作者 (^^)時間15年前 (2010/01/14 15:31), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
※ 引述《AROOBA (捲舌阿魯巴)》之銘言: : 在下使用JQuery的$.ajax : 在document ready的時候用GET去拿response.php的結果回來可正常執行 : 可是使用POST就拿不到任何的回應 : 附上程式碼 : ------------------------------------------------ : $.ajax({ : url: 'response.php', : type: 'GET', // ->改為POST : dataType:"jsonp", ^^^^^ http://docs.jquery.com/Ajax/jQuery.ajax Note: All remote (not on the same domain) requests should be specified as GET when 'script' or 'jsonp' is the dataType (because it loads script using a DOM script tag). Ajax options that require an XMLHttpRequest object are not available for these requests. The complete and success functions are called on completion, but do not receive an XHR object; the beforeSend and dataFilter functions are not called. 看起來 jsonp 是透過 script tag 載入的 , 所以當然只能用 get。 你應該要直接寫 json 就好 而不是jsonp : data:{id:'test'}, : error: function(xhr) { : alert('Ajax request error from all'); : }, : success: function(response) { : alert(response.status); : } : }); : ------------------------------------------------ : 以下為response.php的程式碼 : <?php : $cb=$_GET[callback]; // ->改為$_POST : $arr['status'] = $_GET['id']; //->改為$_POST : $arr['result'] = 'true'; : echo $cb."(".json_encode($arr).");"; : ?> : ------------------------------------------------- : 上面的程式碼在頁面讀完後會alert內容為test的視窗 : 但是改為POST之後就沒反應了 : 有請板上的高手們指點一下迷津 <(__ __)> -- What do you want to have ? / What do you have? 從書本中,你可以發現我的各種興趣。 從CD中,你可以瞭解我所喜歡的偶像明星。 或許從文字你很難以瞭解一個人,但從物品可以。 My PPolis , My past. http://ppolis.tw/user/Tony -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 74.207.224.18

01/14 16:11, , 1F
多謝T大~先去試看看~
01/14 16:11, 1F
文章代碼(AID): #1BJiXcBh (Ajax)
文章代碼(AID): #1BJiXcBh (Ajax)