我問你一個問題。
我需要決議來自 Prestashop WebService 的 JSON。
目前我已經在本地保存了所有 JSON,在一個檔案中,我將它顯示在一個表中并且它可以作業。
我正在使用的代碼是這樣的:
/// Read JSON
<script>
$ ('# loan'). DataTable ({
ajax: {
url: 'products.json',
dataSrc: 'products'
},
"columns": [
{"data": "name"},
{"data": "active"},
{"data": "description"}
]
});
</script>
我的問題是:如何直接使用 url ( https://www.mywebsite.com/shop/api/products/?ws_key=ws_key?&output_format=JSON&display=full ) 而不是使用上述方法?
謝謝。
uj5u.com熱心網友回復:
我希望其中之一有幫助:
使用卷曲
$url = 'https://www.mywebsite.com/shop/api/products/?ws_key=ws_key?&output_format=JSON&display=full';
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,$url);
$result=curl_exec($ch);
curl_close($ch);
var_dump(json_decode($result, true));
使用 AJAX
$.ajax({
type:"GET",
url: "https://www.mywebsite.com/shop/api/products/?ws_key=ws_key?&output_format=JSON&display=full",
success: function(data) {
console.warn(data);
},
error: function(jqXHR, textStatus, errorThrown) {
alert(jqXHR.status);
},
dataType: "jsonp"
});???????????????
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/350324.html
標籤:javascript 阿贾克斯 网页服务 商店
