trouble with ajax pagination inside already ajaxed page

Discussion in 'JavaScript' started by tanyania, Jul 7, 2011.

  1. #1
    I have got an ajax paginatoin script working but I'm having trouble getting into my already ajaxed page

    so I have a link that loads a page into a div into my main page that link loads data from a mysql db

    the ajax pagination works if it's on a page by itself but if I try to load it into the ajaxed div element it does not load the data
     
    tanyania, Jul 7, 2011 IP
  2. tolas

    tolas Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Ya, you need to manually execute any javascript in any AJAX-loaded html.
    Can be a bit of a hassle. It's done by walking (looping over) the .children of your ajax-populated div (so after div.innerHTML = ajaxResult), checking if any div.children.tagName.toUpperCase()=='SCRIPT', en then executing the relevant code by doing eval(div.children.innerHTML);

    Maybe better to send over a JSON data structure that seperates the HTML you're sending (in that first ajax req that populates your div) from any javascript that you want executed after the ajax call completes.
    You'd use it like this;
    var json = eval ('('+ajaxResult+')');
    div.innerHTML = json.html;
    eval (json.javascript);
     
    tolas, Jul 9, 2011 IP