简体   繁体   中英

Access response from jQuery.get() or jQuery.ajax()

I get the response from a file using $.get()

$.get('filename.svg', function (response) {
    console.log(response);

    return response;
});

When I log response I see something like this

#document
    <svg ...>
        <g>....</g>
    </svg>

I wanted to ask how I could access a #document ? property. and print <svg></svg> tag without #document

To clarify what I need that exactly for. I need to calculate SVG size using getBBox()

You can use $.ajax() and supply dataType to be text

$(function(){
    $.ajax({
        url: 'filename.svg',
        dataType: 'text'
    }).then(function (response) {
        console.log(response);
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM