1

I'm trying to load an ajax page and based on success, i want to populate certain divs on my page with returned ajax content. How do i pull this off?

$.get('mypage',function(data){

  $('#1').html($(data #1r).html()) //grab from returned content <div id="1r">blah</div>
  $('#2').html(data #2r).html() //grab from returned content <div id="2r">blah</div>

});

<div id="1"></div>
<div id="2"></div>

Any help would be greatly appreciated... thanks all!

damien

Damien
  • 4,093
  • 9
  • 39
  • 52

2 Answers2

2

Try this,

$('#1').html($(data).find('#1r').html());

Add some characters in id of div instead of using just numbers, read more about characters an id would have in this post.

The value must be unique amongst all the IDs in the element's home subtree and must contain at least one character. The value must not contain any space characters, Reference

$('#r1').html($(data).find('#1r').html());
Community
  • 1
  • 1
Adil
  • 146,340
  • 25
  • 209
  • 204
  • This doesn't seem to work. I get an error, although if i do $('#1').html(data), that will come through fine :\ – Damien Apr 30 '13 at 15:35
  • Yes you have id 1 r1 wont work, you would rename id 1 to r1 to make it work. – Adil Apr 30 '13 at 15:37
  • i didn't even noticed it was changed. Those aren't the real div names i'm using, just used them here to make them easier to type. Using the real divs, it does not work. Uncaught Error: Syntax error, unrecognized expression then it shows my html results – Damien Apr 30 '13 at 15:51
0

Try this -

$('#1').html($(data).find('#1r').html());
$('#2').html($(data).find('#2r').html());
Adil Shaikh
  • 44,509
  • 17
  • 89
  • 111
  • This doesn't seem to work. I get an error, although if i do $('#1').html(data), that will come through fine :\ – Damien Apr 30 '13 at 15:35