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

前端 未结 10 1616
时光说笑
时光说笑 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:55

    How about some quick tag renaming?

    $.ajax({
        type : "GET",
        url : 'results.html',
        dataType : "html",
        success: function(data) {
    
            data = data.replace(/html/g, "xhtmlx");
            data = data.replace(/head/g, "xheadx");
            data = data.replace(/title/g, "xtitlex");
            data = data.replace(/body/g, "xbodyx");
    
            alert($(data).find("xtitlex").text());
        }
    
    });
    

提交回复
热议问题