使用jQuery加载变量php页面

时间:2011-10-19 15:27:20

标签: php jquery html

我的目标是从任何php页面加载div。我正在使用jQuery函数.load:

    $(document).ready(function(){
        $('#crumb').load('example.php #hello');
    });
    </script>

我希望example.php是welcome.php或test.php或about.php。它取决于索引容器中加载的页面。有什么想法吗?

2 个答案:

答案 0 :(得分:0)

试试这个:

function $_GET(q, s) { 
    s = s ? s : window.location.search; 
    var re = new RegExp('&'+q+'(?:=([^&]*))?(?=&|$)','i'); 
    return (s=s.replace(/^?/,'&').match(re)) ? (typeof s[1] == 'undefined' ? '' : decodeURIComponent(s[1])) : undefined; 
}

/*
 * Edited here
 */
$(document).ready(function(){
    $('#crumb').load(($_GET('p') !== undefined ? ('index.php?p=' + $_GET('p')) : 'welcom.php') + ' #hello');
});

答案 1 :(得分:0)

为此,请考虑以下事项:

的Javascript

function GetDiv(url,tdiv) {
$("#GetDivResult").load(url,function() {
HandleResult(tdiv);
});
}
function HandleResult(tdiv){
$("#crumb").html($(tdiv).html());
}
function StartNow(){
var url = prompt("Enter the URL");
var tdiv = prompt("What DIV you want to show? example: #hello");
GetDiv(url,tdiv);
}

HTML

<a href="#" onclick="StartNow()">Begin</a>
<div id="GetDivResult" style="display: none;"></div>
<div id="crumb"></div>

这是一个简单的例子,因此你可以了解它背后的想法..