这对我而言是新东西,请耐心等待。 JQuery & json - 我一直在使用json &序列化在PHP中的“年龄”,但只是进入JQ。我想通过数据跨域 - 所以json数组似乎对我最好,但如何显示它,例如
说我有一个JSON数组像这样在PHP创建了位于http://domain1.com/examplearray.php
$catarray = array('Animal Life','Business & Finance','Cars & Vehicles','Entertainment & Arts','Food & Cooking','Health','History, Politics & Society','Hobbies & Collectibles','Home & Garden','Humor & Amusement','Jobs & Education','Law & Legal Issues','Literature & Language','Relationships','Religion & Spirituality','Science','Shopping','Sports','Technology','Travel & Places');
$callback = json_encode($catarray);
我明白,我可以从另一个域调用它的页面名称examplearray.php说http://domain2.com
$(document).ready(function(){
$.getJSON("http://domain1.com/examplearray.php?callback=",
function(data){
$.each(data, function(i,item)
{
// WHAT DO I put in here to read the array? i.e. what are the keys etc. //
// I assume the display is something like $('#element').html('something');
});
});
});
在上面的示例中,如果您遵循该示例,则没有“设置”键,但现在像这样向该阵列添加一个键
$catarray = array('keyname' => array('Animal Life','Business & Finance','Cars & Vehicles','Entertainment & Arts','Food & Cooking','Health','History, Politics & Society','Hobbies & Collectibles','Home & Garden','Humor & Amusement','Jobs & Education','Law & Legal Issues','Literature & Language','Relationships','Religion & Spirituality','Science','Shopping','Sports','Technology','Travel & Places'));
非常感谢,非常感谢。