【问题标题】:AJAX Post request URL getting weird characters addedAJAX Post 请求 URL 添加了奇怪的字符
【发布时间】:2011-12-14 07:43:39
【问题描述】:

我现在一直在尝试制作这个跨浏览器发布语句,但我收到以下错误:

 $.ajax({
            type: 'POST',
            url: "http://ourdevtest.com/foo/foo",
            contentType: "application/x-www-form-urlencoded; charset=utf-8",
            data: form.serialize(),
            success:function(result, textStatus, xhr) {
                form.hide();
                console.log('success in preview form');
                console.log("result: " + JSON.stringify(result));
                console.log("textStatus: " + textStatus);
                console.log("xhr: " + JSON.stringify(xhr));
                app.showThankYou();
            },
            dataType: 'json'
            });
        });
        },

返回控制台错误:POST http://%E2%80%8B/%E2%80%8B/%E2%80%8Buser:%E2%80%8Bpassword@ourdevtest.com/%E2%80%8Bfoo/%E2%80%8B1/%E2%80%8Bfoo/%E2%80%8B

它无法加载此 URL,但我不知道如何阻止它添加奇怪的字符。

【问题讨论】:

  • %E2%80%8b 是â...奇数的url编码字节形式。

标签: javascript jquery ajax json


【解决方案1】:

试试这个

首先删除

contentType: "application/x-www-form-urlencoded; charset=utf-8", 

形成你的 ajax 调用

试试看

success:function(result, textStatus, xhr) {
      alert("result: " + JSON.stringify(result));              
}

【讨论】:

    【解决方案2】:

    如果您解码该错误响应,您将得到以下字符串:http://​/​/​user:​password@ourdevtest.com/​foo/​1/​foo/

    我认为您应该尝试直接使用某些字段值,而不是使用 form.serialize(),仅用于测试目的。

    【讨论】:

      猜你喜欢
      • 2019-05-20
      • 1970-01-01
      • 1970-01-01
      • 2013-06-24
      • 1970-01-01
      • 1970-01-01
      • 2013-12-13
      • 2021-04-01
      • 1970-01-01
      相关资源
      最近更新 更多