I need help with loading function in JQuery

Currently I have links w / class = "ajax" that I want to get in the id = "test" element from the "data.html" file in the same directory and put this content in the id = content "div on my page :

<script>
$(document).ready(function(){
    $("a.ajax").click(function(event){
    $("#content").load("/data #test");
    });
});
</script>
<a class="ajax" href="#">Text</a>
<div id="content"></div>

      

and externally, but in the same directory, I have data.html:

<div id="test">Will this show up?</div>

      

When you click on the anchor, Safari reports a "page overload" and no change occurs.

I am definitely calling JQuery on the header. Can I get some help with this feature? Thanks!

+1


a source to share


2 answers


You have /data

but a file /data.html

if you are at root. :)



I just checked what you have with this change and it works great for me. I also recommend that you get a tool like Firebug so you can easily see what your AJAX requests are doing.

+1


a source


$.ajax(
{
url : "data.html",
type: "POST",
success: function( answer) 
         { 
           $( "main_content").html( $(answer).find("div#content_id").html( )); 
         }
});

      



Hope this helps you.

0


a source







All Articles