Dilak
Dilak

Reputation: 105

Include a php page in a DIV using JQuery

I am having trouble including a php page in a div after an Ajax call.

I want to include page.php in the div with id=content on an Ajax success function

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

function load(a, b) {
    $.ajax({
        url: "page.php",
        type: "POST",
        data: {
            "a": a,
            "b": b
        },
        success: function(data) {
            console.log(data);
            $("#content").load("page.php"); //What am I doing wrong here?
            return false;
        },
        error: function(jqXHR, error_string, error) {
            console.log(error);
        }
    });
}

Upvotes: 0

Views: 77

Answers (1)

thchp
thchp

Reputation: 2384

When you call page.php with $.ajax, the variable datacontains the page contents. So you just have to append the page contents to your div.

$('#content').append(data);

Upvotes: 1

Related Questions