先判断返回的数据是否存在,再进行处理。
示例代码:
$.ajax({ url: "test.php", dataType: "json", success: function(data){ if (typeof data === "undefined") { console.log("返回数据为空"); } else { // 处理返回的JSON数据 } }, error: function(){ console.log("请求失败"); } });
下一篇:Ajax调用后更改按钮中的文本