JQuery Ajax获取返回html中指定的内容

比如search功能,输入关键字,在数据库中查找对应的包含关键字的记录并显示在页面上,在一段Ajax请求之后,返回html text。。。

 

需要在返回的html中找到指定id的内容用来更新页面中的对应的html内容。。。

 

比如页面:

 

   <div id="test">
    <c:forEach var="solution" items="${mySolutions}">
        <div class="solution">
            <div class="span-1"><img src="${pageContext.request.contextPath}/resources/images/SolutionItem.png"></img></div>
            <div class="span-18">
                <div class="solutionName"><a href="view/${solution.id}">${solution.name}</a></div>
                <div class="solutionDescription">${solution.shortDescription}</div>
            </div>
            <div class="span-2" id="tag_${solution.id}">
                <div>
                    <a href="#" οnclick="addTag('${solution.id}')">add</a>
                    more
                </div>
                <div><textarea style="width:75; height:25; overflow: auto;" rows="3" cols="5">111111111</textarea></div>
                <div><textarea style="width:75; height:25; overflow: auto;" rows="3" cols="5">222222222</textarea></div>
                <div><textarea style="width:75; height:25; overflow: auto;" rows="3" cols="5">333333333</textarea></div>
            </div>
            <div class="span-3 last"><img src="${pageContext.request.contextPath}/resources/images/sample-solution.jpg" class="solutionIcon" alt="Solution Icon"></img></div>
   
            <div class="span-24 last solutionSplitter">
                <hr/>
            </div>
        </div>
    </c:forEach>
</div>

 

 

这个时候采用ajax局部更新:

如下:

 

$.ajax({
	type : "POST",
	url : 'test.jsp',
	dataType : "html",
	success: function(data) {
	    alert( data ); // shows whole dom
	    //alert( $(data).find('#test').html() ); // returns null
            $("#test").html($(data).find("#test").html());


        },
	error : function() {
	    alert("Sorry, The requested property could not be found.");
	}
});







http://api.jquery.com/jQuery.ajax/#options



 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值