$.ajax ex.message,jQuery.ajax response data is undefined

I just faced a similar problem.

Investigating the response in Developer tools, i see that even though the parameter data was passed as 'undefined' to the 'success' function call - the actual response body did contain the expected string.

The response can be deeper investigated in the developer tools

-Network Tab -> press 'Start Capturing' - and on the actual request record - click on 'Go to detailed view').

The problem on my side resided in malformed Content-Type headers of the response. The response string was passed correctly, and was even correctly interpreted in other browsers (FF, Chrome, Safari).

The headers set up on the server were, in this order:

Response.AddHeader "Content-type", "text/html;charset=UTF-8"

Response.AddHeader "Content-type","application/json"

Response.ContentType = "application/json"

The result received by the client (investigated in network detailed view, like above mentioned) was:

Content-Type text/html;charset=UTF-8,application/json

It seems that IE (8,9) is picky about the headers, specifically the Content-Type.

This lead in IE9, IE8 to the parameter data being passed as undefined

and complete subsequent failure.

As soon as i removed the unwanted headers, i.e. this line:

Response.AddHeader "Content-type", "text/html;charset=UTF-8"

The final conten-type received by the client was only:

Content-Type application/json

And finally, the data parameter in this part of the ajax call was no longer "undefined", but the expected "object"

success: function(data, textStatus, XMLHttpRequest){

alert(typeof(data));

},

*

The server-side scripting language in this case is ASP's VBscript, you should know your corresponding syntax for the server-side header setting in order to know what to look for

*

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值