1

i am using ajax to get some data over to my page and use .html() to change the html content of a div. Everything works fine in firefox , google chrome , safari , opera except INTERNET EXPLORER.

IE 7 , 8 , 9 are not responding to the .html() funciton, the contents of that div remains unchanged.

here's my code:

var userurl = $('#userthumb a').attr('href');
$(document).ready(function(){
     $('#userthumb').after("<div id='to-change'>Loading...</div>");
         $.ajax({
            type: "GET",
            url: "parse.php",
            data: "url=" + userurl,
            dataType: 'json',   
            cache: false,
            success: function(data)
             { 
                var respond = data['respond'];       
                  $('#to-change').html(respond + 'profile');
             } //end of success
          }); //end of ajax
});

is there any problems or is there a way to solve the IE problem?

sm21guy
  • 626
  • 3
  • 13
  • 33
  • What does the HTML that's being returned look like? Missing a tag can wreak havoc on IE. – Andrew Whitaker Nov 16 '11 at 03:12
  • Duplicated with http://stackoverflow.com/questions/412734/jquery-html-attribute-not-working-in-ie – ComfortablyNumb Nov 16 '11 at 03:13
  • just a JSON {"respond":"username"} – sm21guy Nov 16 '11 at 03:13
  • When you find yourself wondering if the unexpected behavior of your code is a bug it is extremely important to establish the bare minimum requirements to reproduce the bug. Obviously the html() function works *most* of the time in IE7 so you should take the time to figure out what is different about your code that, apparently, breaks it. Once you have done that you should post all relevant snippets so that we can determine if indeed it's a bug or perhaps one of us sees something you aren't. As it stands it is likely no one can help you because you didn't even post the html code. – Spencer Ruport Nov 16 '11 at 03:16
  • okay i will double check my code – sm21guy Nov 16 '11 at 03:17

3 Answers3

0

Try this: $('#to-change').empty().append(respond + 'profile');

dm7
  • 81
  • 1
  • 4
0

Try

  $('#to-change').html($.parseJSON(data).respond + 'profile');
Kai
  • 2,967
  • 1
  • 22
  • 28
0

This might solve it:

success: function(data) { 
    eval('var jSON = '+data);
    $('#to-change').html(jSON['respond'] + 'profile');
} //end of success

EDIT: Make sure your returning data is in the format, for example:

{'respond':'it worked as expected','.....':'....'}

In my vbscripts I return:

response.write "{'Success':'MoveOn','....':'....'}"   or
response.write "{'Success':'Error:........','....':'....'}"

Then,

eval('var jSON='+data);
if (jSON['Success'] == 'MoveOn') .......
zequinha-bsb
  • 719
  • 4
  • 10
  • it returns an error " missing ] after element list" var jSON = [Object object]; – sm21guy Nov 16 '11 at 03:51
  • i use this in php , is that correct , im getting an 505 error $results = array('respond'=>'0','success'=>'0'); echo json_encode($results); – sm21guy Nov 16 '11 at 04:11
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/5034/discussion-between-sm21guy-and-zequinha-bsb) – sm21guy Nov 16 '11 at 04:12