ajax post无法进行,无法获得jQuery ajax POST的工作

如果我在下面的代码中将type设置为’GET’,则可以使用,但无法将其与’POST’一起使用。

ajaxPostTest.html …

$(document).ready(function(){

$.ajax({

url: "ajaxPostTest_server.php",

data: {"fruit1": "rasp", "fruit2": "bramble"},

type: 'POST',

dataType: 'json',

contentType: "application/json; charset=utf-8",

success: function(data){

$("#returned").append(data.fruit1);

},

error: function(jqXHR, textStatus, errorThrown){

alert("error") ;

}

});

});

returned:

ajaxPostTest_server.php …

echo json_encode($_REQUEST);

?>

浏览器上的预期输出为…

returned: rasp

我实际上是在尝试与ASP.NET Web服务器进行交互,并且我想先确认我的ajax是否可以正常工作(并且我对ajax的理解正确),因此可以简化此代码。

Firebug调试…

Response Headersview source

Date Fri, 23 Sep 2011 14:57:37 GMT

Server Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_color PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1

X-Powered-By PHP/5.3.1

Keep-Alive timeout=5, max=99

Connection Keep-Alive

Transfer-Encoding chunked

Content-Type text/html

Request Headersview source

Host localhost

User-Agent Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.18) Gecko/20110614 Firefox/3.6.18

Accept application/json, text/javascript, */*; q=0.01

Accept-Language en-gb,en;q=0.5

Accept-Encoding gzip,deflate

Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7

Keep-Alive 115

Connection keep-alive

Content-Type application/json; charset=utf-8

X-Requested-With XMLHttpRequest

Referer http://localhost/My_Webs/temp/ajaxPostText1.html

Content-Length 26

Cookie PHPSESSID=mgvoacnluh3kad5pakafrd5kd1

我在[回应]标签中得到的只是…

{"PHPSESSID":"mgvoacnluh3kad5pakafrd5kd1"}

即我找不到我发送到服务器的数据要去的地方。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值