我正在尝试从我的服务器提供的其他页面加载 JSON。这是我的 JavaScript 代码:
$('#checkprice').click(function(){
$.get('{{route('userinventory')}}',function(data){
console.log('test')
},'json');
});
现在,这个:
{{route('useriventory)}}
工作正常,它只是为我生成网址,当我访问它时,这是我得到的数据类型:
[{"assetid":"8522812062","classid":"720539092","itemname":"\u2605 Bayonet | Doppler (Factory New)","name_color":"8650AC","price":156.34},{"assetid":"8516603597","classid":"721320736","itemname":"\u2605 StatTrak\u2122 M9 Bayonet | Marble Fade (Factory New)","name_color":"8650AC","price":540}]
我认为我的 JSON 数据很好,url/userinventory 命中只返回 json 编码数组的方法。当我尝试在 JS 中获取它时,由于某种原因它不起作用。首先我尝试了 json.get 现在尝试使用 ajax 相同的结果(什么也没有发生)
最佳答案
只需按照 $.get documentation 操作即可jquery 的。第二个参数是数据参数。所以你的代码应该像这样工作:
$('#checkprice').click(function(){
$.get('{{route('userinventory')}}',{},function(data){
console.log('test')
},'json');
});
关于javascript - jQuery 从 HTTP 请求中获取 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41350915/