0

I have the following code

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
</head>
<body>

<button id="btn1">Get JSON data</button>
<div></div>

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>

<script>
$(document).ready(function(){
    $.support.cors = true;
  $("#btn1").click(function(){

    //$.getJSON("https://graph.facebook.com/LavanReddy",function(result,textStatus,jqXHR){
    //  $.each(result, function(key, value){
    //   $("div").append(key+": "+value+"<br />"); 
    //  });
    //}).fail(function(xhr, status, error)  
    //{
    //  alert('Error: ' + status + '\nError Text: ' + error + '\nResponse Text: ' + xhr.responseText);
    //});
    $.ajax({
        type: 'GET',
        url: 'https://graph.facebook.com/LavanReddy',                       
        contentType: "application/json; charset=utf-8",                 
        dataType: 'json',                   
        success: function(result) { 
            $.each(result, function(key, value) {
                $("div").append(key+": "+value+"<br />"); 
                });
        },
        error: function(xhr, status, error) {
                alert('Error: ' + status + '\nError Text: ' + error + '\nResponse Text: ' + xhr.responseText);
        }
    });                                     

  }); 

});
</script>
</body>
</html>

I tried using both getJSON as well as Ajax (no luck). It works correctly on all browsers in local. But on server it works only on chrome, firefox and IE10 but not on IE8 or IE9 Plz help

user3233516
  • 3
  • 1
  • 3
  • 2
    You can debug your app using Debug Tools included on IE (press F12) and can also switch between IE versions. – Fran Verona Jan 24 '14 at 20:58
  • I did. I used fiddler as well, i don't see any errors there. Javascript error message "Type Error: Access is denied" is immediate. – user3233516 Jan 24 '14 at 21:38
  • Where do you get that error message? In localhost? You should debug your app in localhost. – Fran Verona Jan 24 '14 at 21:57
  • I cannot.I tried both F12 as well as fiddler. All i can say i dont see any error. I see an alert(from my code) is Error: error Error Text: TypeError: Access is denied. Response Text: undefined. I can access the same this way C:\inetpub\wwwroot\test.html and it works fine. – user3233516 Jan 27 '14 at 15:37
  • when i acess this http://localhost/test.html it fails. I provided all the code. I believe it works for you too. Please help. – user3233516 Jan 27 '14 at 15:44
  • I test your code and did some research. See my answer below :) – Fran Verona Jan 27 '14 at 19:01

2 Answers2

1

I search a little bit on StackOverflow for your problem, and I think that I found a solution.

Ajax Requests to Facebook graph not working on IE

It seems like a problem with JSON treatment by IE or something. Just add ?callback=? as a parameter to your query in order to force JSONP instead of pure JSON.

Your code should look like:

$.ajax({
     type: 'GET',
     url: 'https://graph.facebook.com/LavanReddy/?callback=?',                       
     contentType: "application/json; charset=utf-8",                 
     dataType: 'json',                   
     success: function(result) { 
         $.each(result, function(key, value) {
             $("div").append(key+": "+value+"<br />"); 
         });
     },
     error: function(xhr, status, error) {
             alert('Error: ' + status + '\nError Text: ' + error + '\nResponse Text: ' + xhr.responseText);
     }
});

I attach an screenshot to prove it:

Code working on IE

My IE version is 9. I can't test it in other versions, but I hope it works.

Happy coding!

Community
  • 1
  • 1
Fran Verona
  • 5,438
  • 6
  • 46
  • 85
  • Fran, Thx for your help. Appreciate it. It works for the following URL, but the URL which i am pointing too (accessible only frm my server) doesn't return JSONP and gives me an error "parsererror" "Error: jQuery19105968480703886598_1390853371790 was not called". this error occurs from both Chrome as well as IE now. FYI: F12 on IE gives an option (Browser mode) to switch between the browser versions. – user3233516 Jan 27 '14 at 20:16
  • It seems like you're calling a function called "jQuery19105968480703886598_1390853371790", but that is a different problem I think. Can't help you too much without source code :) – Fran Verona Jan 27 '14 at 21:37
  • All i have is the same code, except that the URL is different (accessible only frm our server (https)). Looks like the that data is not JSONP enabled so the callback in the url can't help me out here. – user3233516 Jan 27 '14 at 22:08
  • A lot of people is having problems with JSON on IE. Try to do a little research on StackOverflow about those topics. Maybe mixing some answers you will find a solution that fits with your code and configuration http://stackoverflow.com/search?q=json+IE. Sorry if I'm not more useful. – Fran Verona Jan 27 '14 at 22:17
0

With at least jQuery version 1.5, just include the jquery.xdomainrequest.min.js script into your page, then make your AJAX call like you normally would

https://github.com/MoonScript/jQuery-ajaxTransport- XDomainRequest/blob/master/jquery.xdomainrequest.min.js

jo v
  • 302
  • 5
  • 14