使用jquery .load打破超链接和图像的URL路径

时间:2018-01-23 16:42:21

标签: javascript php jquery

尝试在论坛上使用评论部分,同时避免使用iframe。

    <script>
    $('#test').load('./forum/viewtopic.php?f=13&t=10' function(result) {
    var variable = $('#result').html();
    $(this).find(".topic-title").remove();
    $(this).find(".action-bar").remove();
    $(this).find(".postprofile").remove();
    </script>

所有指向site.com/forum/linkhere.php的链接现在指向site.com/linkhere.php,这包括我在标题中调用脚本的所有内容,因此所有ajax表单基本上都是无用的。我试过像这样的重写

$('#test a').each(function(){
$(this).prop('src', path + '/' + $(this).prop('src'))

并尝试$('#test script'),同时也path + '/forum',但没有运气。这个内容刚刚被推送到id =“test”的div。

有人给我一些提示吗?

$(function() {
        $('script').each(function() {
            $(this).attr('text/javascript', function(index, value) {
                if (value.substr(0,1) !== "/") {
                    value = window.location.pathname + value;
                }
                return "https://site[dot]com/forum" + value;
            });
        });
    });
});

更新:我通过设置PHPBB_ROOT_PATH赢得了一些运气:'../ forum';在viewtopic.php中,这修复了我的相对路径问题,并开始正确加载所有标头。但是现在一旦通过ajax表单提交帖子,帖子就会成功提交,但是刷新ajax页面会出错。装入带有jquery的div。任何想法可能是什么?我认为这是一个jquery / .load问题,因为该表单在实际论坛页面上运行良好。

1 个答案:

答案 0 :(得分:-1)

使用完整路径网址 http://yoursite.com/forum/linkhere.php 为你的每一个电话 viewtopic.php文件

-edit:

尝试在根文件夹中使用httacces文件 检查这个帖子:

Using .htaccess to redirect all pages except three