为什么我的AJAX load()不能在这段代码中工作?

时间:2013-05-06 21:23:13

标签: html ajax dom

我有一个脚本,可以将html页面中的ul加载到另一页面上的div。它应该是我的导航菜单,但它不会加载。 ul有一个id名称,我使用id加载ul而不加载ul所在的整个html页面。

//This is the page I want the ul to load to.

    <body>
     <div id="fb-root"></div>
<script>

  //facebook registration init code omitted

</script>



//this is the div where I want the ul to load

<div id="nav">

</div>

// in this div is the facebook registration plug in iframe that shows after the fbinit code runs.

<div>
<iframe src="https://www.facebook.com/plugins/registration?
             client_id=3967*****188&&
             redirect_uri=http://myDomain.com/signedRequest.php&
             fields=name,password"
        scrolling="auto"
        frameborder="no"
        style="border:none"
        allowTransparency="true"
        width="100%"
        height="330">
 </iframe>

    </div> 


         <button>Button label</button>

// jqueru UI method
<script>
$(function(){
 $( "button" ).button(); 

});
</script>

//The rest of the page markup omitted

</body>
</html>   

//this is the script where I call the load()
//The load to #mainDiv is for use on another page
//note that I'm only trying to load the ul with id navig, and not the whole html page. 

$(function(){

$("#mainDiv").load("http://myDomain.com/find2.html");

$('#nav').load("http://myDomain.com/menu.html #navig");

});   

//this is the menu.html page with the ul. 

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>

<ul id="navig">
    <li><a href="#"> gatherings I'm hosting</a></li>
    <li><a href="#"> gatherings I'm invited to</a></li>
</ul>

</body>
</html>     

1 个答案:

答案 0 :(得分:1)

修复此问题,似乎地址格式错误: $('#nav').load("http://myDomain.com/menu.html #navig");

#navig只是一个哈希,在SERVER-SIDE中无效,对于应用程序client-side

祝你好运