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. html - vue項目中用到了elementUI問題2. 對mysql某個字段監控的功能3. javascript - windows下如何使用babel,遇到了困惑4. javascript - js中向下取整5. JavaScript事件6. showpassword里的this 是什么意思?代表哪個元素7. android - rxjava多線程并發怎么控制順序8. java - Spring MVC怎么實現提交表單后跳轉?9. python - 為什么正常輸出中文沒有亂碼,zip函數之后出現中文編程unicode編碼的問題,我是遍歷輸出的啊。10. javascript - table列過多,有什么插件可以提供列排序和選擇顯示列的功能
