javascript - ajax接受json瀏覽器顯示xml解析錯誤:格式不佳?
問題描述
用火狐在本機上測試的ajax
ajax:
(function(){ for(let selectPage = 1; selectPage <= pagesNumber; selectPage++ ) { if(selectPage != page) { btn[selectPage].onclick = function(){ var result = $.ajax({ url: ’./something.json’, // :./asset/host_last data: {'selectPage': selectPage}, dataType: ’JSON’, type: ’get’, success: function(){ console.log('success'); } }); console.log(result.responseText); }; } } })();
something.json:
{ 'IP地址':'something', '主機名':'something', '產品':'something', '應用':'something', '機柜編號':'something', '使用狀態':'something', '備注':'something'}
問題解答
回答1:file協議,請別這么使用,你得json是正確的,但是如果你使用file協議,不是http協議,那么響應頭信息你應該看看,雖然請求頭是JSON,你可以試一試跑一下http協議
| | | )_) )_) )_) )___))___))___))____)____)_____) _____|____|____|______
--------- /--------- ^^^^^ ^^^^^ ^^^^ ^^^^^^^ ^^^^^ ^^^
相關文章:
1. docker images顯示的鏡像過多,狗眼被亮瞎了,怎么辦?2. 關docker hub上有些鏡像的tag被標記““This image has vulnerabilities””3. docker-machine添加一個已有的docker主機問題4. css - 求推薦適用于vue2的框架 像bootstrap這種類型的5. Span標簽6. SessionNotFoundException:會話ID為null。調用quit()后使用WebDriver嗎?(硒)7. android新手一枚,android使用httclient獲取服務器端數據失敗,但是用java工程運行就可以成功獲取。8. css - 關于div自適應問題,大家看圖吧,說不清9. redis啟動有問題?10. java - Collections類里的swap函數,源碼為什么要新定義一個final的List型變量l指向傳入的list?
