首页 文章

load()和getscript()并不总是有效

提问于
浏览
1

在我的index.php页面上,我使用jquery load()在div“bodycontent”中加载其他页面 . 这工作得很好,花花公子 . 我禁用常规链接,并且必须使href成为页面名称,而不是php,并在load()发生时将php重新标记为 . 我在div中加载的一个页面我在链接上弹出了对话框 .

当你最初去页面时,这很好,但是如果你通过点击“产品”或页面上的任何其他链接而转向,然后返回“主页”并点击链接“阅读更多” ,对话框不会再出现 . 您必须刷新,然后它将一直有效,直到您再次单击链接 . 此外,这在我的IE 9,ver9.0.8中运行良好,但是工作中的旧IE(如8),并且至少有一个其他人镀铬对话框根本不会出现 . 尽管我删除了临时互联网文件等,但在我的工作中还有IE9,这将无法解决 . 在我的电脑上它可以正常运行firefox,chrome和IE的全新下载,所以我也想知道我的方法是否向后兼容并且是否跨浏览器,如果不是我可以做到这一点 . 我也在一个带负载的函数中使用get脚本来拉取jquery,jquery ui和我的javascript文件用于对话框 .

我也看过像ajaxcomplete这样的东西,但是我最初的作品,我不知道该怎么做 .

My site main index page loading home.php initially (the news, ect)

Fiddle with my navigation javascript, which makes the pages inactive/active and load()/getscript in the div

dialog.js:

$(document).ready(function() {
$('#dialogbox').dialog({
    autoOpen: false,
    title: 'Loading title...', 
    modal: true,
    width: 500,
    height: 400
});
});
function readMore(id,title,cat,desc,post,auth) { 
//alert(id +","+ title +","+ cat +","+ desc +","+ post +","+ auth); 
var $dialog = $('#dialogbox').html('Category: '+ cat +'
'+ desc +'
---------------------------------
Posted by: '+ auth +'
' + post); $dialog.dialog('open'); $dialog.dialog("option","title",title); }

我如何拉动函数readMore:

<?php
                require('config/dbconfig.php');
                $query = "SELECT * FROM news ORDER BY id DESC LIMIT 4";
                if ($stmt = $mysqli->prepare($query)) {
                    /* execute statement */
                    $stmt->execute();

                    /* bind result variables */
                    $stmt->bind_result($idn, $titlen, $categoryn, $descn, $postdaten, $authorn);

                    /* fetch values */
                    while ($stmt->fetch()) {
                        //echo 'id: '. $id .' title: '. $title;
                        echo "<table border='0'>";
                        $shortDescLengthn = strlen($descn);
                        if ($shortDescLengthn > 106) {
                            $sDCutn = 106 - $shortDescLengthn;
                            $shortDescn = substr($descn, 0, $sDCutn);
                        } else {
                            $shortDescn = $descn;
                        }
                        echo "<h1>$titlen</h1>"; 
                        echo "<tr><td>$shortDescn...</td></tr>"; 
                        echo '<tr><td><a href="javascript:void(0);" onclick="' 
                        . 'readMore(' . $idn . ',' . htmlspecialchars(json_encode($titlen)) . ',' 
                        . htmlspecialchars(json_encode($categoryn)) . ',' 
                        . htmlspecialchars(json_encode($descn)) . ',' . htmlspecialchars(json_encode($postdaten)) . ',' 
                        . htmlspecialchars(json_encode($authorn)) . ')">Read More</a></td></tr>'; 
                        echo "<tr><td>Written by: $authorn</td></tr>"; 
                        echo '<tr><td><img src="images/hardcore-games-newsbar-border.png" width="468px" /></td></tr>'; 
                    }
                    echo "</table>
"; /* close statement */ $stmt->close(); } /* close connection */ $mysqli->close(); ?>

所以,基本上我需要看看为什么在点击链接后这不起作用,以及它如何可以更多地跨浏览器和向后浏览器兼容 .

1 回答

  • 0

    我所要做的就是添加:

    $('#bodycontent').empty();
    

    在load()之前,它适用于我迄今为止尝试过的每台计算机 . 我猜想在加载新的html之前需要清空div,所以回去它就是保留js等来自getscript并弄乱了 . 还只保存了仅由home.php所需的单个js文件,并将其他所有内容放在索引页面中(就像它本应该一样) .

相关问题