jquery ajax parse response text

前端 未结 5 1691
执念已碎
执念已碎 2020-12-03 12:19

Ok this is really frusturating me because I\'ve done this a hundred times before, and this time it isn\'t working. So I know I\'m doing something wrong, I just can\'t figur

5条回答
  •  半阙折子戏
    2020-12-03 12:45

    Wanting to do the same thing and knowing that JQuery load(..) does it, I had a look in the code. While you can't turn a complete html response directly into a JQuery object, you can append it to one so:

    function(data, textStatus, xhr) {
        $(target).html(jQuery("
    ").append(data).find("#snippet")); // Create a dummy div to hold the results, // inject the contents of the document into it, // Locate the specified elements }

    The response from the server that goes into data is like:

    
    
      
        ...
      
      
        

    Some content here that we are interested in

提交回复
热议问题