3

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.

lonesomeday
  • 233,373
  • 50
  • 316
  • 318
Kelly Elton
  • 4,373
  • 10
  • 53
  • 97
  • 2
    This will be a hard one to troubleshoot, as IE10 is still in beta. – TNC Jun 27 '12 at 22:28
  • Strictly speaking, the `encodeURIComponent` calls should be unnecessary, since jQuery will do that for you. – lonesomeday Jun 27 '12 at 22:41
  • was using it without, doesn't fix anything. – Kelly Elton Jun 27 '12 at 22:44
  • compare console inspection of request to IE9 or IE8 view of same and see what differences are. Also add error handler to $.ajax. `"not working"` isn't a lot of info to work from – charlietfl Jun 27 '12 at 23:00
  • I can see the problem in my code (that do not use JSON code, but used 'object.varible = value'), and other people can repro. – Moshe L Dec 28 '12 at 11:46

6 Answers6

3

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

VahidN
  • 18,457
  • 8
  • 73
  • 117
0

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)});
Moshe L
  • 1,797
  • 14
  • 19
0

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" >
Md. Nazrul Islam
  • 2,809
  • 26
  • 31
0

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

henryP
  • 1
0

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)

cardy
  • 103
  • 1
  • 10
-2

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.

marteljn
  • 6,446
  • 3
  • 30
  • 43
  • http://api.jquery.com/jQuery.post/#example-1 $.post("test.php", { name: "John", time: "2pm" } ); – Kelly Elton Jun 28 '12 at 00:33
  • 1
    email and pass would work if you didn't name a variable email and pass. So if you don't put it in quotes the key will be the value of that variable. – marteljn Jun 28 '12 at 00:34
  • Gotcha, thing is though, you can't type {email,pass}, can you? – Kelly Elton Jun 28 '12 at 01:00
  • 2
    No but this is a valid object literal `{"email":email, "password":pass}`, so code it exactly like that. And as a correction this is issue is only with the email one. Your password should work as is. I know what you mean by the JQuery doc but it works just as well as I wrote it above. – marteljn Jun 28 '12 at 01:03
  • Works on ie9, must be a bug. Good advice anyways though. – Kelly Elton Jun 28 '12 at 01:20
  • 1
    Keys in Javascript object literals can be unquoted providing they are not reserved words. Neither `email` nor `password` is reserved. Therefore the problem with IE10 must lie elsewhere - not immediately obvious what it might be. – Beetroot-Beetroot Jun 28 '12 at 07:29
  • 1
    That said, [this page](http://www.javascripter.net/faq/reserved.htm) recommends avoiding `password` (and many other non-reserved words). – Beetroot-Beetroot Jun 28 '12 at 07:43
  • This is still an issue with IE10 RTM which i'm using now. Infact I couldn't post this comment in IE10 standard mode and had to switch to IE9 mode! – Andrew Harry Oct 08 '12 at 00:39
  • @AndrewHarry I'm having the same problem here. I had to force my site into IE9 mode to keep it working.. :-/ – Nicholas Head Nov 13 '12 at 17:18
  • Same problem here. IE 10 tries to download json post. – Mike Dec 11 '12 at 00:03
  • Why is this wrong? At the time a fresh copy of internet explorer and jquery would cause this issue. I believe IE10 was barely out the door though, so they could have squashed the bug making your answer irrelevant I suppose. What answer would you propose as the right one? – Kelly Elton May 14 '14 at 16:33
  • @kelton52 I re-updated it to state that it may no longer be applicable instead of 'wrong'. – marteljn May 14 '14 at 16:47