1 回答

TA貢獻(xiàn)1863條經(jīng)驗(yàn) 獲得超2個(gè)贊
ajax返回的數(shù)據(jù)判斷為空和普通的判斷是否為空是一樣的,直接使用if語句判斷即可。
工具原料:編輯器、瀏覽器
1、后臺(tái)傳輸?shù)臄?shù)據(jù)一般為Json字符串,如果數(shù)據(jù)為空則直接傳輸空字符串或者直接給其他的標(biāo)識(shí)符來讓前端區(qū)分。
2、簡單的代碼示例如下:
1 2 3 4 5 6 7 8 9 10 11 12 | $.ajax({ type:"post", url:"test.html", success:function(data){ //參數(shù)data是后臺(tái)傳回來的數(shù)據(jù) if(data==''){ alert("數(shù)據(jù)為空"); }else{ //做相關(guān)的解析處理 } } }); |
3、如果是標(biāo)識(shí)符如狀態(tài)碼判斷可能是這樣的,假設(shè)數(shù)據(jù)為空給一個(gè)字段為status的值我10000。
1 2 3 4 5 6 7 8 9 10 11 12 | $.ajax({ type:"post", url:"test.html", success:function(data){ var data =JSON.parse(data); if(data.status==100000){ alert('數(shù)據(jù)為空'); }else{ //相關(guān)處理 } } }); |
- 1 回答
- 0 關(guān)注
- 496 瀏覽
添加回答
舉報(bào)