What is the best practice for parsing remote content with jQuery?

前端 未结 10 1602
时光说笑
时光说笑 2020-11-27 03:21

Following a jQuery ajax call to retrieve an entire XHTML document, what is the best way to select specific elements from the resulting string? Perhaps there is a library or

10条回答
  •  日久生厌
    2020-11-27 04:01

    Inspired from this answer, but with deferred:

    function fetchDoc(url) {
      var dfd;
      dfd = $.Deferred();
    
      $.get(url).done(function (data, textStatus, jqXHR) {
    
        var $iframe = $('