[英]How to use if-else condition in return Json to table use trHtML +=
$.ajax({
type: "POST",
dataType: "json",
url: "/section/search_go",
data: { query: search_string },
cache: false,
success: function(response) {
console.log("Got " + response.length + " results");
if (response.length === 0) {
$("#customers").html(no_results_str);
} else {
var trHTML = "";
$.each(response, function(i, item) {
trHTML += "<tr>";
trHTML += "<td>" + item.accountnumber + "</td>";
trHTML += "<td>" + item.company + "</td>";
trHTML += "<td>" + item.phone + "</td>";
trHTML += "<td>" + item.postcode + "</td>";
/// want to use
if (item.status = 1) {
echo "Complete";
}else{
echo "Non Complete";
}
*/////////////////////////////////
trHTML += "</tr>";
});
$("#customers").html(trHTML);
}
}
});
您正在使用變量響應,但可以將其定義為length屬性。
試試吧
if(! response typeof undefined)
代替
if(response.length === 0)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.