Cannot use jQuery.get () to get html content.

I want to get the html content of another page, so I use the following jquery.get () function

$.get("chk_vga.aspx", function(data) {
    alert($('#vga').html());
});

on the page "chk_vga.aspx", it has only one value

<html>
    <body>
        <div id="vga">F</div>
    </body>
</html>

how will my jquery function get the value "F"?

+3
source share
4 answers

To access the content, you must add it to the element.

$.get("chk_vga.aspx", function(data) {
    var foo = jQuery("<div></div>").html(data).find("#vga").html();
    alert(foo);
});
+1
source
.load('chk_vga.aspx #vga', function(data) {
    alert(data);
});
+3
source

Here's what you do is the alert()parent's internal HTML. If you use this code, you will get #vga internal HTML from the #vga div on the remote page.

$.get('chk_vga.aspx', function(data) {
    alert(data.match(/id="vga">(.[^\"]*)<\/div>/i)[1]);            
});

OR

$.get('chk_vga.aspx', function(data) {
    alert(data);
});
+1
source
$("#aSolucoes").click(function(e) {
            e.preventDefault();
            mostrarCarregando();
            $("#divModal").load('Consulting.aspx', aposCarregamento);

        });

        function mostrarCarregando() {
            $("#divModal").css('display', 'block').fadeIn(1000);
        };

        function aposCarregamento() {
            $("#divModal").reveal({
                animation: 'fadeAndPop',                   //fade, fadeAndPop, none
                animationspeed: 300,                       //how fast animtions are
                closeonbackgroundclick: true,              //if you click background will modal close?
                dismissmodalclass: 'close-reveal-modal'    //the class of a button or element that will close an open modal
            });
        };
0
source

All Articles