Jquery 如何使用ajax success中的.html()插入标记?
我使用ajax,成功后如果data.length小于200,我希望对标记html进行一些更改Jquery 如何使用ajax success中的.html()插入标记?,jquery,html,Jquery,Html,我使用ajax,成功后如果data.length小于200,我希望对标记html进行一些更改 $('#…').html()正常,但$('#…').html(“…”)不是工作模式 我能找人帮忙找出我的错误吗 对不起,我英语不好 <!-- html code --> <table> <colgroup> <col style="width: 200px;" /><!-- 별점 --> <col
$('#…').html()
正常,但$('#…').html(“…”)代码>不是工作模式
我能找人帮忙找出我的错误吗
对不起,我英语不好
<!-- html code -->
<table>
<colgroup>
<col style="width: 200px;" /><!-- 별점 -->
<col style="width: 300px;" /><!-- 제목 -->
<col style="width: auto;" /><!-- 내용 -->
</colgroup>
<thead>
<tr>
<th class="txt_center">추천별점</th>
<th class="txt_center">제목</th>
<th class="txt_center">내용</th>
</tr>
</thead>
<tbody id="review_list">
</tbody>
</table>
<!-- script code -->
$.ajax({
type: "get",
url: "/search/get_goods_review",
data : {"location":location},
success: function(data) {
$('#review_list').html(data);
if($('#review_list').html().length < 200){
$('#review_list').html("<tr><td colspan='5' style='text-align:center;'>리뷰 정보가 없습니다.</td></tr>");
}
},
error: function(xhr, stat, err) {
alert("실패");
}
});
추천별점
제목
내용
$.ajax({
键入:“获取”,
url:“/search/get\u goods\u review”,
数据:{“位置”:位置},
成功:功能(数据){
$('review#u list').html(数据);
if($('#查看列表').html().length<200){
$('#查看列表').html(“리뷰 정보가 없습니다.");
}
},
错误:函数(xhr、stat、err){
警报(“실패");
}
});
我认为您必须进行如下更改(更改已注释):
$.ajax({
键入:“获取”,
url:“/search/get\u goods\u review”,
数据:{“位置”:位置},
成功:函数(响应){//始终使用不同的名称来消除歧义
如果(response.length<200){//检查response.length是否小于200
$('#查看列表').html('리뷰 정보가 없습니다.'); //是,然后替换HTML
}否则{
$('#review_list').html(response);//否则粘贴即将到来的响应
}
},
错误:函数(xhr、stat、err){
警报(“실패");
}
});
我认为您必须进行如下更改(更改已注释):
$.ajax({
键入:“获取”,
url:“/search/get\u goods\u review”,
数据:{“位置”:位置},
成功:函数(响应){//始终使用不同的名称来消除歧义
如果(response.length<200){//检查response.length是否小于200
$('#查看列表').html('리뷰 정보가 없습니다.'); //是,然后替换HTML
}否则{
$('#review_list').html(response);//否则粘贴即将到来的响应
}
},
错误:函数(xhr、stat、err){
警报(“실패");
}
});
Easy and quick to test if$(“#…).html(“..”)
通过注释除$(“#review_list”)之外的所有ajax代码为您工作。html(“Easy and quick to test if$(“#…)”
通过注释除$(“#review_list”)之外的所有ajax代码为您工作。html(“@유효림 很高兴帮助您:)@유효림 很高兴帮助您:)
$.ajax({
type: "get",
url: "/search/get_goods_review",
data : {"location":location},
success: function(response) { //always use different names to remove ambiguity
if(response.length < 200){ //check response.length less that 200
$('#review_list').html('<tr><td colspan="5" style="text-align:center;">리뷰 정보가 없습니다.</td></tr>'); //yes then replace HTML
}else{
$('#review_list').html(response); //otherwise paste coming response
}
},
error: function(xhr, stat, err) {
alert("실패");
}
});