weixin_33675507 2013-11-03 16:19 采纳率: 0%
浏览 2

jQuery .load(); 不工作

This is my first time trying this.

I have the following code in the head of an ajax.html:

$(document).ready(function(){
   $( "#result" ).load( "/loaded.html" );
});

Then in the same directory, I have a second page, loaded.html:

<div id="result">Hello!</div>

However #result is not loaded. I have double checked jQuery, and it's all plugged in.

Would anyone know what is going wrong?

  • 写回答

1条回答 默认 最新

  • ??yy 2013-11-03 16:22
    关注

    It should be:

    $("selector to load into").load("loaded.html #result");
    

    You apply .load() to the DIV you want to load into. If you want to search in the loaded data for a specific DIV, put that selector after the URL.

    And since you're loading from the same directory, don't put / at the beginning of the URL. That means to load from the webroot directory.

    评论

报告相同问题?