日期:2014-05-16  浏览次数:20355 次

如何利用js跨域查询json数据并放置在html页面中,希望高人能把代码贴出来
1.我现在有一个这样的api地址他返回的是json格式的数据
http://api.cndns.com/sitestar/getTemplateCategories.aspx?username=cantect&otime=201302281136&checksum=5d3742d59bb86347d71b7145a6615f61

2.我想获取他的status的值,但是我不知道从何下手

3.这是我用jquery写的获取json的测试页面,通过firebug的调试,证明我get了json数据,但是显示不了
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>test.html</title>

    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript" language="javascript" src="js/jquery-1.7.2.js"></script>
 
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script>
 function showStudent(){
     var s='';
  $.getJSON("http://api.cndns.com/sitestar/getTemplateCategories.aspx?username=cantect&otime=201302281136&checksum=5d3742d59bb86347d71b7145a6615f61",function(json){
   var d=json.status;

  for(var i=0;i<d.length;i++){
    //循环输出p标签 
    s+=('<p>id:'+d[i].status +'&nbsp;&nbsp;');
  }
  $('#content').html(s);
 });
 


 </script>

 
  </head>
  
<body>
<input type="button" value="获取json" onclick="showStudent()" />
<div id="content"></div>
</body>
</html>
json 跨域?jquery firebug html

------解决方案--------------------

$(function(){
$.ajax({
type:'GET',
url:'http://api.cndns.com/sitestar/getTemplateCategories.aspx?username=cantect&otime=201302281136&checksum=5d3742d59bb86347d71b7145a6615f61' ,
dataType:'jsonp',
success:function(data){
console.log(data);
}});
});




好像不行,建议LZ用JAVA或PHP去获取,然后用ajax去调用对应的后台程序。
------解决方案--------------------
<script type="text/javascript" src="javascript/jquery-1.4.2.min.js"></script>
<script> 
$(document).ready(function() 
        {
 
        //从校务系统取得学校新闻
        var shoolwebsite = "http://10.1.8.199:801/school/InterFaceWebService.asmx/GetSchoolNotice2_jsonSerialization?callback=?";
        $.getJSON(