![](/img/trans.png)
[英]what is proper way to import multiple components from same file in react instead of getting each component imported
[英]What is the proper way in getting data from a json file?
從我的json文件中獲取數據的正確方法是什么? 結果總是不確定的
項目名稱:未定義項目密鑰:未定義
.json文件
[{"item_id":"1","item_name":"Book","item_key":"290Q12"}]
我的腳本,jQuery
var item_name;
var item_key;
var item_id = '<?php echo $row->item_id; ?>';
var get_loc = '<?php echo base_url();?>index.php/main/get_one_item_info/';
item();
function item() {
$(document).ready(function () {
$.ajax({
type: 'GET',
url: get_loc + item_id,
data: { get_param: 'value' },
success: function (data) {
for (var i=0;i<data.length;++i)
{
item_name = data[0].item_name;
item_key = data[0].item_key;
document.getElementById("items").innerHTML = "Item name: " + item_name + "<br>Item key: " + item_key + " ";
}
}
});
});
setTimeout(item, 2500);
};
的index.php
<div id='items'></div>
您也可以嘗試
$url = 'your url';
$obj = json_decode(file_get_contents($url), true);
$item_name = $obj['item_name'];
$item_key = $obj['item_key'];
// print_r($obj);
您可以將$ .getJSON()方法與上面提到的文件名一起使用...。
$.getJSON('link of json file',function(response){
// action to be performed
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.