jquery ajax $.post not working IE10

2019-02-25 12:31发布

I've tried this two ways.

Way 1

function Login() {
    var email = encodeURIComponent($("#loginemail").val());
    var pass = encodeURIComponent($("#password").val());
    $.ajax({
        url:"/user/login",
        type: "POST",
        data: {email:email, password:pass},
        dataType: "json"
    }).done(LoginDone);
    //$.post("/user/login", {email:email, password:pass}, LoginDone);
}

Way 2

    function Login() {
        var email = encodeURIComponent($("#loginemail").val());
        var pass = encodeURIComponent($("#password").val());
        $.post("/user/login", {email:email, password:pass}, LoginDone);
    }

Both ways work fine on chrome, but for some reason with IE it doesn't send the data {email:email, password:pass} in the POST, or at all.

I've tried both on a local server, and on a live webserver, both with the same results.

Using IE10 here.

6条回答
太酷不给撩
2楼-- · 2019-02-25 12:56

data: {email:email, password:pass}

should be

data: {"email":email, "password":pass}

You are passing the value of the variables as the key so if your server-side resource is expecting email it is actually seeing the value of that variable encodeURIComponent($("#loginemail").val()).

This is likely not an IE10 issue, this shouldn't work as written in any browser.

Update

This answer may no longer be applicable due to bug fixes in IE 10.

Please disregard this answer it is wrong and cannot be deleted due to being accepted.

查看更多
爷的心禁止访问
3楼-- · 2019-02-25 13:03

After deep debuggind I found a workaround for IE10 AJAX POST Bug:

do not use POST with GET.

$.post("Page.aspx?action=edit",a,function(data) {dataRow[0]=data; GoToShowMode(row)});

change to

a.action=edit;
$.post("Page.aspx",a,function(data) {dataRow[0]=data; GoToShowMode(row)});
查看更多
唯我独甜
4楼-- · 2019-02-25 13:14

Try this: http://code.gishan.net/code/solution-to-ie10-ajax-problem Works for me. This is a known issue of IE10.

查看更多
一纸荒年 Trace。
5楼-- · 2019-02-25 13:16

Can't fix @jQuery bug tracker: AJAX Post on IE10 / Windows 8

查看更多
爷的心禁止访问
6楼-- · 2019-02-25 13:16

IE-10 does not work data serialize => $(this).serialize()

 $('#formLogin').submit(function () {

        $.ajax({
            url: this.action,
            type: this.method,
            data: $(this).serialize(),
            cache: false,
            success: function (data) {

                var val1 = "";
                var val2 = "";

                $.map(data, function (item) {
                    val1 = item.success;
                    val2 = item.URL;
                });

                if (data[0].messageCode == "success") {
                    GoGO(data[0].URL);
                }
                else {
                    alert(data[0].message);
                }
            }
        });
        return false;
    });

For this you can use this line on _layOut.chtml before metatag. So, IE-10 works just like IE-9.

  <meta http-equiv="x-ua-compatible" content="IE=9" >
查看更多
来,给爷笑一个
7楼-- · 2019-02-25 13:17

I've had the same problem with IE 10 (10.0.9200.16521) on Win7 x64 SP1. I've solved the problem simply by using a newer version of jQuery (1.9.1 in place of 1.8.3)

查看更多
登录 后发表回答