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

前端 未结 10 1565
时光说笑
时光说笑 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 03:38

    Just an idea - tested in FF/Safari - seems to work if you create an iframe to store the document temporarily. Of course, if you are doing this it might be smarter to just use the src property of the iframe to load the document and do whatever you want in the "onload" of it.

      $(function() {
        $.ajax({
          type: 'GET', 
          url: 'result.html',
          dataType: 'html',
          success: function(data) {
            var $frame = $("