您的位置:首頁技術文章
文章詳情頁

javascript - ajax接受json瀏覽器顯示xml解析錯誤:格式不佳?

瀏覽:95日期:2023-02-22 15:03:07

問題描述

用火狐在本機上測試的ajaxjavascript - ajax接受json瀏覽器顯示xml解析錯誤:格式不佳?

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協議

| | | )_) )_) )_) )___))___))___))____)____)_____) _____|____|____|______

--------- /--------- ^^^^^ ^^^^^ ^^^^ ^^^^^^^ ^^^^^ ^^^

標簽: JavaScript
相關文章:
国产综合久久一区二区三区