简体   繁体   中英

Ajax is not working (don't know why)

Hi and thanks to everybody in advance!

I want to do a simple thing with Ajax but is not working: push the button and change the html with another one from the same folder. Is something with the javascript but I can't identify the problem. I'm quite a novice with web design.

$(".about .ajax").on("click",function(e){

var section = $(this).closest("section");

var href = $(this).attr("href");

$.ajax({
    url:href,
    dataType:"html",
    success:function(data){

        var contenido = $("#about",data);

        section.html(contenido);
    }
});
e.preventDefault();

});

jsfiddle

I don't think you are binding it back properly.

I think you want something like this:

success:function(data){
    $("#about").html(data);
}

Passing data as the 2nd argument will restrict jquery to find the right element.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM