如何在使用JSON调用加载数据时执行JavaScript请求?
<script src="http://code.jquery.com/jquery-1.10.1.js"></script>
<style>
li:target {
width:222px;
height: 222px;
}
.blok {
display: block;
width: 99px;
height: 99px;
float: left;
position: relative;
background: #888;
margin: 2px;
}
</style>
<script>
$(document).ready(function(){
$('#outputData.li[id^="go"]').each(function(e){
$(this).attr('num',e+1);
$(this).click(function(e){
num = parseInt($(this).attr('num'));
loc = window.location+"";
pos = loc.indexOf('#');
if(pos>-1){
loc = loc.substring(0,pos);
};
loc = loc + '#go'+num;
window.location = loc;
});
});
});
</script>
</head>
<body>
<div id='content' class="clickable clearfix">
<!--
<ol>
<li id="go0" class='blok bestof'><a href="#go0">####</a></li>
<li id="go1" class='blok jq php'><a href="#go1">jq php I 2.1</a></li>
</ol>
//-->
<ol>
<div id="outputData"></div>
</ol>
</div>
评论的行显示它确实有效。但是在调用数据时没有JSON。 目标是通过使用JSON单击初始方块(不仅仅是链接)上的ANYWHERE来打开(放大)一个框。
app_v3.php文件:
<?php
header('Content-type: application/json');
$ray=array('prodData'=> array(
'8'=> array('id'=>'8','title'=>'bestof','category'=>'bestof'),
'2'=> array('id'=>'2','title'=>'jq','category'=>'php'),
'3'=> array('id'=>'3','title'=>'html','category'=>'css'),
'4'=> array('id'=>'4','title'=>'php','category'=>'css'),
'5'=> array('id'=>'5','title'=>'css','category'=>'html'),
'6'=> array('id'=>'6','title'=>'php','category'=>'html'),
'7'=> array('id'=>'7','title'=>'jq','category'=>'html'),
));
//print"<pre>" . print_r($ray) . print"</pre>";
echo $_GET['jsoncallback'] . '(' . json_encode($ray) . ');';
?>