GET request in AJAX-retrieved HTML

Posted by ufw on Stack Overflow See other posts from Stack Overflow or by ufw
Published on 2010-03-14T18:52:30Z Indexed on 2010/03/14 18:55 UTC
Read the original article Hit count: 417

Filed under:
|

There is some HTML code which appears on the page as the result of AJAX request/response. This HTML contains GET requests to another php script. Links containing this requests are not working while "real" HTML (added on the page manually) works normally.

When I open the page source with Ctrl+U I see empty div's (but they actually have HTML retrieved via AJAX) and the full-fledged HTML code added manually. Can't figure out how can I make the AJAX-retrieved links working.

This is how I try to form the HTML code which must be added to the page as the result of AJAX response.

<?php

//some selections from the database...
//all subsequent varibles are the members of $row=(mysql_fetch_array($query)) array;

$html_to_be_inactive = 
    '<li id="productID_' . $productID . '">
        <a href=work.php?action=deleteFromBasket&productID=' . $productID . ' onClick="return false;">
        <img src="images/delete.png" id="deleteProductID_' . $productID     . '">
        </a> ' . $productName . '(' . $totalItems . ' items) - $' . ($totalItems * $productPrice) . '</li>';

 echo $html_to_be_inactive;
?>

And that is it, result of 'echo' appears on the page after successful AJAX request as the simple HTML, and it does nothing when I click the link.

I do not perform DOM 'append' methods as I'm not familiar with DOM yet. I can see all the elements mentioned in $thml_to_be_inactive but the link seems to be really inactive. Also this HTML is absent in the "Ctrl+U" output, I can see it only when I select "Inspect element" in the browser.

The HTML which was added manually operates the same items as usual, but I need AJAX-retrieved HTML to be working as well.

I suspect I need to perform some 'append' method via JavaScript or jQuery, but I don't know how to do it in a proper way.

Thanks.

© Stack Overflow or respective owner

Related posts about AJAX

Related posts about html