Aravind30790
Aravind30790

Reputation: 992

Getting div contet from Ajax response

I used this query to make the ajax call

$j.ajax({
    url: durl,
    context: document.body,
    dataType: 'html',
    complete: function(data) {
        console.log(data.responseText);
        var aa = $j(data).filter('#outputMessage').text();
        console.log(aa);
    }
});

the response text printed on the console has

<div id ="outputMessage">
    Could not process transactions. 
</div>

i used both filter and find which prints empty string on the console. Am i doing something wrong here . How can i get the div content message from the ajax response

Upvotes: 0

Views: 67

Answers (3)

Aravind30790
Aravind30790

Reputation: 992

After trying lot of things , I finally figured it out by using like this

$j(data.responseText).filter('#outputMessage').text()

Upvotes: 0

jpk
jpk

Reputation: 189

Have you tried like below ?

var aa = $j(data.responseText).html();
console.log(aa);

Upvotes: 0

Satpal
Satpal

Reputation: 133403

As data.responseText has the required content.

You need to use

$j(data.responseText).find('#outputMessage').text()

instead of

$j(data).find('#outputMessage').text()

Upvotes: 1

Related Questions