作者TonyQ (^^)
看板Ajax
标题Re: [问题] $.ajax可以使用get但是无法使用post
时间Thu Jan 14 15:31:47 2010
※ 引述《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
1F:推 AROOBA:多谢T大~先去试看看~ 01/14 16:11