這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)碛嘘P(guān)決ajax異步請(qǐng)求返回的是字符串如何解決,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
1.返回結(jié)果差異
js獲取后打印res.code無結(jié)果。因?yàn)榉祷財(cái)?shù)據(jù)格式不正確。
php文件添加header頭:
header('Content-Type:application/json;');
或者。j s 添加
contentType: "application/json; charset=utf-8", dataType: "json", $.ajax({ url:'../data/insert_category.php?article_type=' + value, contentType: "application/json; charset=utf-8", dataType: "json", success:function(res){ console.log('異步成功'); console.log(res); console.log(res.code); }, error:function(){ console.log('異步失敗'); } })
上述就是小編為大家分享的決ajax異步請(qǐng)求返回的是字符串如何解決了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。