DN0300
DN0300

Reputation: 876

Loading a page in div using jquery and ajax

I am trying to open content into a div on click, I can't figure out where I am going wrong any help is much appriciate. Thank you
Html:

    <li><a id="hrefid" href="#link">Link</a></li> 

<div id="content"> </div>

Jquery:

$('#hrefid').on('click', function (e) {
    var load = $(e.target).attr("href");
    if(load == "#link") {
        $.ajax({
            type: 'post',
            url: "/page/test/272.html",
            complete: function (event) {
                $("#content").contents().remove();
                $("#content").append(event.responseText);
            }
        });
    }
    });

Upvotes: 0

Views: 77

Answers (2)

Nadeem Manzoor
Nadeem Manzoor

Reputation: 750

jquery load will be much better option, try the following code

$('#hrefid').on('click', function (e) {
    var load = $(e.target).attr("href");
    if(load == "#link") {
        $( "#content" ).load( "/page/test/272.html", function() {
             //anything after load is complete
         });
    }
});

Upvotes: 0

Ahsan
Ahsan

Reputation: 2518

Your intended operation is a GET operation as far as i understand, so instead of type: 'post' make it type: 'get'

Upvotes: 2

Related Questions