开发者

GET request in AJAX-retrieved HTML

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开发者_StackOverflow'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.


  1. You need to put your href in quotes.
  2. onClick="return false;" will override the default action (go to href) of your link. You need to bind an other event to the link, or just remove `return false'.


Your links use relative paths.

You're probably inserting the HTML into a page in a different directory, breaking the relative paths.

If so, you need to switch to absolute paths.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜