代码之家  ›  专栏  ›  技术社区  ›  oshirowanen

在附加时编辑结果?

  •  1
  • oshirowanen  · 技术社区  · 14 年前

    我有以下脚本,它将从服务器端页面返回的数据显示到客户端页面:

    function getResults() {
        var search; 
        search = $(".txtSearch").val(); 
    
        $.ajax({
            url: 'search.aspx',
            type: 'POST',
            data: { strPhrase:search },
            error: function(xhr, status, error)
            success: function(results) 
            { 
                $("#ResultsContainer").empty(); 
                $("#ResultsContainer").append(results); 
            }
        });
    }
    

    是否可以检查追加时返回的结果并对其进行更改?

    例如,假设返回的结果是HTML,如下所示:

    <div><a href="link1.xls">link 1</a></div>
    <div><a href="link2.xls">link 2</a></div>
    <div><a href="link3.doc">link 3</a></div>
    <div><a href="link4.xls">link 4</a></div>
    

    是否可以检查链接中的.doc并删除该特定链接周围的完整DIV,只留下以下内容?

    <div><a href="link1.xls">link 1</a></div>
    <div><a href="link2.xls">link 2</a></div>
    <div><a href="link4.xls">link 4</a></div>
    
    4 回复  |  直到 14 年前
        1
  •  5
  •   user113716    14 年前

    success: function(results) 
        { 
            var $results = $(results);
            $results.find('a[href$=doc]').parent().remove();
            $("#ResultsContainer").empty().append($results); 
        }
    

    results

    jQuery's .find() method <a> attribute ends with doc

    .parent() calls .remove()

    the .append() method $results

        2
  •  0
  •   Chowlett    14 年前
        3
  •  0
  •   fcalderan    14 年前

        4
  •  0
  •   Alin P.    14 年前

    onInteractive - (Not guaranteed) Triggered whenever the requester receives a part of the response (but not the final part), should it be sent in several packets.