pee2pee
pee2pee

Reputation: 3792

jQuery Get DIV Content From Another Page

I have the following code:

<script>
$( document ).ready(function() {
$("div.imp-1 span.field-content").each(function() {
    var $li = $(this);
    var href = $li.find("a").attr("href") + ".htm";  // use this in your real case
    //console.log (href);
    $.ajax({
        type: "POST",
        success: function(data) {
            var time = $(data).find('.time-default').html();
            $li.append(" - " + time);
        }
    });
});

});
</script>

The HTML page has some HTML as follows

<div class="time-default">22:15 - 23:30</div>

It keeps returning "undefined" - what am I doing wrong?

Thanks

Upvotes: 0

Views: 7691

Answers (1)

Satpal
Satpal

Reputation: 133403

You need to pass other page URL.

$.ajax({
    url: href,  //Pass URL here 
    type: "GET", //Also use GET method
    success: function(data) {
        var time = $(data).find('.time-default').html();
        $li.append(" - " + time);
    }
});

Upvotes: 2

Related Questions