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協議
| | | )_) )_) )_) )___))___))___))____)____)_____) _____|____|____|______
--------- /--------- ^^^^^ ^^^^^ ^^^^ ^^^^^^^ ^^^^^ ^^^
相關文章:
