Php returns thickbox link that doesn't work

两盒软妹~` 提交于 2019-12-12 20:46:32

问题


I'm running into a bit of an issue when I try to return a link to pull up a thickbox on my page from a simple php echo. Basically what I have is:

A page with a few include statements like:

<?php 
    include ("display_header.php");
?>

Each one of the include statements just points to a php file that pulls a short query and echos out a link with an anchor ref to open an inline thickbox (with a form) when the user clicks on the link text like:

echo "<a href='#TB_inline?height=265&width=225&inlineId=header_change' class='thickbox' style='text-decoration:none; color:#990000'>";
echo "Query Result etc";
echo "</a>";

So when the user clicks on the link on the page, a thickbox with a form is supposed to pop up. The user enters their changes to the given section, clicks submit, and jquery ajax posts the form and reloads the div with the include statement to display the changes.

This works the first time the page is loaded, but once I submit the form and try to click on the returned link again nothing happens. This seems to work if I have the link surround the div with the include statement inside (which isn't a big deal to do), but I just don't understand why this doesn't work if I have the link in the included php statement.

Can anyone offer some guidance? I know there are a lot of brilliant people here and I'm probably just not understanding something very basic. Thanks!


回答1:


You need to bind thickbox to your links using Events/live. Something like:

$("a.thickbox").live("click",function() {
    tb_init('a.thickbox');
});

That will prevent your thickbox enabled links from losing their binding to thickbox after they are reloaded or injected via ajax.

You can also do it in the callback to your $.ajax (or $.post or whatever) method, e.g.:

$.ajax({
    type:       "GET",
    url:        "/ajax-content.php",
    cache:      false,
    data:       "f=foo&b=bar",
    loading:    $('.loading').html(''),
    success:    function(html) {
                    $('#ajaxContent').html(html);
                    //re-attach thickbox
                    tb_init('a.thickbox, area.thickbox, input.thickbox');
                }
});



回答2:


It sounds like this is a javascript problem and not a php problem.

It sounds like to me you register an event when the page loads and once the ajax event is complete, you are not reregistering the event. I can't know that without seeing the javascript though.



来源:https://stackoverflow.com/questions/1249130/php-returns-thickbox-link-that-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!