0

I am having a strange issue with an AJAX call where it is working in Firefox, but not in IE. When I add an IE alert(), I see the returned content, but it does not want ot insert with the jQuery .html() command. Here is my sample code:

$(document).on('click','.OpenForm',function(e) {    
    e.preventDefault();
    var FormControl = $(this).attr('id');       //ex: id=FormView_12 or FormEdit_12
        FormControl = FormControl.split('_');
    var FormControlType = FormControl[0];
    var FormID = FormControl[1];
    $.post("./includes/Getform.php", { "t" : "view" , FormID : FormID })  
     .done(function(data) {
      if (data.length>0){
        data = data.replace(/(\r\n|\n|\r)/gm,"");
        //alert(data); ---THIS ALERTS THE RESPONSE IN IE8
        //console.log(data); --- THIS SHOWS RESPONSE IN FF
        $('.ProjectContentLoad').html(data).show();
      }
   })
   .fail( function(xhr, textStatus, errorThrown) {
      error_handling(xhr.responseText);
   });
});
Nate23VT
  • 423
  • 8
  • 27

3 Answers3

1

Perhaps your returned HTML is invalid. FF doesn't have problems with that, but IE8 sure does ;) Maybe you forget to close a div?

The following post shows some guys having the exact same problem: jQuery AJAX GET html data IE8 not working

Community
  • 1
  • 1
Kim Hogeling
  • 641
  • 6
  • 14
  • Seems so simple but that was the problem - I had a in the wrong place. Thanks everyone for the help! – Nate23VT Oct 22 '13 at 20:57
0

Do you have any error message on your JS console ? Can you show what data content is ?

I'm thinking about 2 things:

1) If you don't run development tools in IE8, console.log() is undefined. To solve it, put this code at the top of your page :

<script type="text/javascript"> if (!window.console) console = {log: function() {}}; </script>

source : 'console' is undefined error for Internet Explorer

2) Maybe an AJAX cache issue with IE (I don't think because you are using post() ), try to put this code at the top of your page :

$.ajaxSetup({ cache: false });

source: How to prevent a jQuery Ajax request from caching in Internet Explorer?

Community
  • 1
  • 1
airdump
  • 643
  • 1
  • 7
  • 15
  • breaking it up into two parts is a bad suggestion. – epascarello Oct 22 '13 at 20:40
  • Oh, yes you're right, `.html( htmlString )` return a JQuery object. http://api.jquery.com/html/#html2, I edit my message. – airdump Oct 22 '13 at 20:47
  • Breaking it up into two parts didn't resolve the issue. ALso added the cache:false command with no luck, checking to make sure the HTML is valid now... – Nate23VT Oct 22 '13 at 20:47
0

Just a shot in the dark, but IE isn't getting confused by the JS object you're sending is it?

{ "t" : "view" , FormID : FormID }

Is there any reason you're using a string as a key for "t"?

Tom Bowers
  • 4,951
  • 3
  • 30
  • 43