目前myArray使用JSON数据进行硬编码。我希望myArray从外部json url读取 http://www.currymasters.com.au/ws/json/products.php
I am not able to do that. Please suggest.
<!DOCTYPE html>
<html>
<body>
<div id="id01"></div>
<script>
var myArray = [
{"file_url":"images/stories/virtuemart/product/chipotle_seasoning.jpg","file_url_thumb":"images/stories/virtuemart/product/resized/chipotle_seasoning_400x400.jpg","product_name":"Chipotle Seasoning","product_desc":"","virtuemart_category_id":"2"},{"file_url":"images/stories/virtuemart/product/paella_seasoning.jpg","file_url_thumb":"images/stories/virtuemart/product/resized/paella_seasoning_400x400.jpg","product_name":"Paella Seasoning","product_desc":"","virtuemart_category_id":"2"},{"file_url":"images/stories/virtuemart/product/peri_peri_seasoning4.jpg","file_url_thumb":"images/stories/virtuemart/product/resized/peri_peri_seasoning4_400x400.jpg","product_name":"Peri Peri Seasoning","product_desc":"","virtuemart_category_id":"2"}];
myFunction(myArray);
function myFunction(arr) {
var out = "";
var i;
for(i = 0; i < arr.length; i++) {
out += '<img height="72" width="72" alt="" src="http://www.currymasters.com.au/testsite/' + arr[i].file_url + '"/><span>' +
arr[i].product_name + '</span><br/>';
}
document.getElementById("id01").innerHTML = out;
}
</script>
</body>
</html>