为什么Web服务器无法解码请求正文

时间:2015-03-09 08:03:23

标签: jquery ajax web

我在微信中有一个网络应用程序,使用jQuery ajax请求web服务器,我发现了一个奇怪的错误,有时 web服务器无法解码ajax请求体,使用Wireshark来捕获HTTP日志,发现原因是每个字节的低位置高位交换,所以web服务器无法解码它。看下面的图片:

正确的:

4D 6F 62 69 6C 65 54 65  6C 3D 31 32 33 34 35 36
37 38 39 39 34

false:

D4 F6 26  96 C6 56 45 56 C6 D3 13
23 33 43 53 63 73 83 93  93 43 

例如。 4D到D4

有人可以告诉我原因吗?

ajax代码:

    var options = {
        url: url_signup,
        type: 'post',
        data: data,
        contentType: "application/x-www-form-urlencoded; charset=utf-8",
        success: function (result) {
            $.openTipLayer({content: "注册成功",callback: function(){
                    if (!!url_success_go) {
                        window.location.href = url_success_go;
                    }
                }
            });
        }
    };
    MySDK.tools.ajax(options);

MySDK.tools.ajax只是简单地包装jquery ajax:

MySDK.tools = {

ajax:function(options){
    options = $.extend({needLoading:true }, options);
    var hasLoading=$(".note").filter(":visible").length>0;
    if(!hasLoading && options.needLoading){
        $.openTipLayer({id:"defaultLoading",content: "",closeTime:0,warpClass:"note_loadwarp2",zIndex:3000,isMask:true});
    }
    var success=options.success;
    options.success=function(result){
        if(!hasLoading && options.needLoading){
            $.closeTipLayer({id:"defaultLoading"});
        }
        if(options.sucesssTopFun){
            options.sucesssTopFun();
        }
        if(!result.result){
            if(result.data==-1){
                var url=window.location.href;
                url=encodeURIComponent(url);
                window.location.href=url_login+"&url="+url;
            }
            else{
                $.openTipLayer({content: result.message});
                if(options.resultFalseFun){
                    options.resultFalseFun();
                }
            }
            return;
        }
        if(success){
            success(result);
        }
    }
    var error = options.error;
    options.error = function (xhr) {
        if(!hasLoading && options.needLoading){
            $.closeTipLayer({id: "defaultLoading"});
        }
        var msg =  "server error, code " + xhr.status;
        $.openTipLayer({content: msg});
        if (error) {
            error();
        }
    }
    $.ajax(options);
},   

0 个答案:

没有答案