$.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);
}
}
});
答案 0 :(得分:0)
您正在使用变量响应,但是可以将其定义为length属性。
尝试
if(! response typeof undefined)
代替
if(response.length === 0)