ajax fails on IE 10 when using json

i am using ajax call to a rest service.

it all works perfectly well on Chrome but when running it from IE 10 the ajax call fails.

I tried to print the error message but i didn't get something enlightening, is just says 'undefined'.

The ajax request is never sent to the server. I saw posts talking about issues of IE with json but didn't find the right solution yet.

something more (don't know if it is relevant): if i try to go to the service url through IE 10 (putting the url in the browser) the JSON is not displayed.Instead it asks me if i want to open a file.

in addition: the request is done from an html file. (not under the same domain as the service).

Any ideas?

Thanks.

   var JSONObject= {
            "login":LogInUserName,
            "password": LogInPassword,
            };


    $.ajax({  
        url:'https .... ',  
        type:'post',
        data :  JSONObject,      
        dataType: 'JSON',
        success: function(data) { 
            if(data.hasOwnProperty('errors'))
                {
                    alert("errors found");
                    alert(data.errors);
                }
            else
                {
                    alert("data sent!");

                }


            }  ,
        error: function (request, status, error)  {
            alert ("error before sending");
            alert(request.responseText);
            location.reload();

        }


    });  

Answers


The first thing you need to do is learn to properly debug and become best friends with F12, the Console tab, and the Network tab:

This tutorial shows Google Chrome but the SAME EXACT idea applies to IE or FireFox

1 - use console.log() instead of alert()
var JSONObject = {
    "login": LogInUserName,
    "password": LogInPassword // get rid of the comma, stop being lazy
};


$.ajax({
    url: 'https .... ',
    type: 'post',
    data: JSONObject,
    dataType: 'JSON',
    success: function (data) {

        // hit F12 and check the console
        console.log(data); // F off alert()!

    },
    error: function (request, status, error) {

        console.log(request); // F off alert()!
        console.log(status); // F off alert()!
        console.log(error); // F off alert()!

        // don't reload, we have an issue
        // location.reload();

    }


});
2 - Get cozy with F12

http://www.degraeve.com/reference/simple-ajax-example.php

  • Press F12
  • Go to Network Tab
  • Type something on the website and hit Go
  • Click on that beast and check for errors in the Response or Preview tabs


Need Your Help

Parse saveInBackgroundWithBlock crashes on iOS

ios parse-platform nszombieenabled

I am adding some data into my parse class (table) successfully.

HTML to SQL sending data while using POST method

c# asp.net sql-server

After setting local server, I want to send data to SQL server from HTML page. I'm using C#, ASP.NET. But the problem is, while I'm using post method, it just showing me blank result without sending