<!-- index.html --><!DOCTYPE html><html><head> <meta charset="utf-8"> <title>ajax</title> <script type="text/javascript"> var xhr = new XMLHttpRequest() xhr.onreadystatechange = function () { if (xhr.readyStage == 4) { if ((xhr.status >= 200 && xhr.status<300) || xhr.status == 304) { console.log(xhr.responseText) }else{ console.log('successful'+xhr.status) } } } xhr.open('get','./test.txt',true) xhr.send(null) </script></head><body></body></html>問題:為什么瀏覽器上無顯示錯誤,且test.txt文件也確實已經(jīng)被加載到瀏覽器端了,卻不能console.log輸出或者alert彈窗。注意:1.文件是放在www目錄下,且服務器也已經(jīng)開啟。2.test.rxt有數(shù)據(jù)。相關(guān)截圖:
ajax輸出問題
慕斯王
2018-12-20 15:15:30