小弟新手,最近学到jsonp和ajax时遇到疑惑。 $.getJSON()中的url是怎么来的???并不是网页的网站啊,还需要各种参数还有callback~~ 这个url是网站提供的开放url来获取json数据的还是怎样的???这个开放的url和各网站的开放平台有关吗????假如我想获取某个新闻网的 一些文章标题做成超链接,也就是获取json数据,我要怎么写url????就结了一天了 ,百度不到答案啊。。问题有点多,请各位大神帮我一次,耐心解答下吧,感激不尽。

解决方案 »

  1.   

    url貌似是你ajax请求的网站吧 
    callback是你请求会数据后做什么吧?
    我是猜的  
      

  2.   

    第一个参数即url
    jQuery.getJSON( url [, data ] [, success(data, textStatus, jqXHR) ] )
    url
    Type: String
    A string containing the URL to which the request is sent.
    data
    Type: PlainObject
    A plain object or string that is sent to the server with the request.
    success(data, textStatus, jqXHR)
    Type: Function()
    A callback function that is executed if the request succeeds.
      

  3.   

    $.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json&jsoncallback=?", 
    function(data){ 
    $.each(data.items, function(i,item){ 
    $("<img/>").attr("src", item.media.m).appendTo("#images"); 
    if ( i == 3 ) return false; 
    }); 
    }); 
    其中http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&amp;format=json&jsoncallback=? 
    返回json数据,然后在回调函数里用$.each遍历json数据的data项数据,最后取出data项数据中item子项的数据……例如返回的json为({
    "title": "Recent Uploads tagged cat",
    "link": "http://www.flickr.com/photos/tags/cat/",
    "description": "",
    "modified": "2013-01-19T23:03:02Z",
    "generator": "http://www.flickr.com/",
    "items": [
       {
    "title": "Sunset #12",
    "link": "http://www.flickr.com/photos/81737232@N03/8395416595/",
    "media": {"m":"http://farm9.staticflickr.com/8353/8395416595_570bef797b_m.jpg"},
    "date_taken": "2013-01-19T17:58:54-08:00",
    "description": " <p><a href=\"http://www.flickr.com/people/81737232@N03/\">►Raquel<\/a> posted a photo:<\/p> <p><a href=\"http://www.flickr.com/photos/81737232@N03/8395416595/\" title=\"Sunset #12\"><img src=\"http://farm9.staticflickr.com/8353/8395416595_570bef797b_m.jpg\" width=\"240\" height=\"180\" alt=\"Sunset #12\" /><\/a><\/p> <p><\/p>",
    "published": "2013-01-19T23:03:02Z",
    "author": "[email protected] (►Raquel)",
    "author_id": "81737232@N03",
    "tags": "ocean trees light boy sunset sky sun moon lighthouse tree eye love portugal nature girl smile clouds cat canon mouth photography glasses photo fishing focus kitten rocks waves peace hand blu obey cap blond moonlight swag moutains supreme vinatge"
       },
       {
    "title": "Sunset #9",
    "link": "http://www.flickr.com/photos/81737232@N03/8395407155/",
    "media": {"m":"http://farm9.staticflickr.com/8095/8395407155_3f1a30ed67_m.jpg"},
    "date_taken": "2013-01-19T18:00:24-08:00",
    "description": " <p><a href=\"http://www.flickr.com/people/81737232@N03/\">►Raquel<\/a> posted a photo:<\/p> <p><a href=\"http://www.flickr.com/photos/81737232@N03/8395407155/\" title=\"Sunset #9\"><img src=\"http://farm9.staticflickr.com/8095/8395407155_3f1a30ed67_m.jpg\" width=\"240\" height=\"180\" alt=\"Sunset #9\" /><\/a><\/p> <p><\/p>",
    "published": "2013-01-19T23:03:04Z",
    "author": "[email protected] (►Raquel)",
    "author_id": "81737232@N03",
    "tags": "ocean trees light boy sunset sky sun moon lighthouse tree eye love portugal nature girl smile clouds cat canon mouth photography glasses photo fishing focus kitten rocks waves peace hand blu obey cap blond moonlight swag moutains supreme vinatge"
       },
       {
    "title": "Ocean",
    "link": "http://www.flickr.com/photos/81737232@N03/8396596866/",
    "media": {"m":"http://farm9.staticflickr.com/8499/8396596866_7cb935cb3f_m.jpg"},
    "date_taken": "2013-01-19T17:18:22-08:00",
    "description": " <p><a href=\"http://www.flickr.com/people/81737232@N03/\">►Raquel<\/a> posted a photo:<\/p> <p><a href=\"http://www.flickr.com/photos/81737232@N03/8396596866/\" title=\"Ocean\"><img src=\"http://farm9.staticflickr.com/8499/8396596866_7cb935cb3f_m.jpg\" width=\"180\" height=\"240\" alt=\"Ocean\" /><\/a><\/p> <p><\/p>",
    "published": "2013-01-19T23:02:39Z",
    "author": "[email protected] (►Raquel)",
    "author_id": "81737232@N03",
    "tags": "ocean trees light boy sunset sky sun moon lighthouse tree eye love portugal nature girl smile clouds cat canon mouth photography glasses photo fishing focus kitten rocks waves peace hand blu obey cap blond moonlight swag moutains supreme vinatge"
       },
       {
    "title": "Clouds",
    "link": "http://www.flickr.com/photos/81737232@N03/8396508296/",
    "media": {"m":"http://farm9.staticflickr.com/8333/8396508296_a522aedcc4_m.jpg"},
    "date_taken": "2013-01-19T17:58:03-08:00",
    "description": " <p><a href=\"http://www.flickr.com/people/81737232@N03/\">►Raquel<\/a> posted a photo:<\/p> <p><a href=\"http://www.flickr.com/photos/81737232@N03/8396508296/\" title=\"Clouds\"><img src=\"http://farm9.staticflickr.com/8333/8396508296_a522aedcc4_m.jpg\" width=\"180\" height=\"240\" alt=\"Clouds\" /><\/a><\/p> <p><\/p>",
    "published": "2013-01-19T23:03:00Z",
    "author": "[email protected] (►Raquel)",
    "author_id": "81737232@N03",
    "tags": "ocean trees light boy sunset sky sun moon lighthouse tree eye love portugal nature girl smile clouds cat canon mouth photography glasses photo fishing focus kitten rocks waves peace hand blu obey cap blond moonlight swag moutains supreme vinatge"
       },
       {
    "title": "Cloud #1",
    "link": "http://www.flickr.com/photos/81737232@N03/8395530223/",
    "media": {"m":"http://farm9.staticflickr.com/8088/8395530223_ffb0d41d55_m.jpg"},
    "date_taken": "2013-01-19T17:10:03-08:00",
    "description": " <p><a href=\"http://www.flickr.com/people/81737232@N03/\">►Raquel<\/a> posted a photo:<\/p> <p><a href=\"http://www.flickr.com/photos/81737232@N03/8395530223/\" title=\"Cloud #1\"><img src=\"http://farm9.staticflickr.com/8088/8395530223_ffb0d41d55_m.jpg\" width=\"180\" height=\"240\" alt=\"Cloud #1\" /><\/a><\/p> <p><\/p>",
    "published": "2013-01-19T23:02:36Z",
    "author": "[email protected] (►Raquel)",
    "author_id": "81737232@N03",
    "tags": "ocean trees light boy sunset sky sun moon lighthouse tree eye love portugal nature girl smile clouds cat canon mouth photography glasses photo fishing focus kitten rocks waves peace hand blu obey cap blond moonlight swag moutains supreme vinatge"
       },
       {
    "title": "IMG_2610",
    "link": "http://www.flickr.com/photos/81737232@N03/8395426447/",
    "media": {"m":"http://farm9.staticflickr.com/8501/8395426447_fac5e5bbfb_m.jpg"},
    "date_taken": "2013-01-19T17:52:39-08:00",
    "description": " <p><a href=\"http://www.flickr.com/people/81737232@N03/\">►Raquel<\/a> posted a photo:<\/p> <p><a href=\"http://www.flickr.com/photos/81737232@N03/8395426447/\" title=\"IMG_2610\"><img src=\"http://farm9.staticflickr.com/8501/8395426447_fac5e5bbfb_m.jpg\" width=\"180\" height=\"240\" alt=\"IMG_2610\" /><\/a><\/p> <p><\/p>",
    "published": "2013-01-19T23:03:00Z",
    "author": "[email protected] (►Raquel)",
    "author_id": "81737232@N03",
    "tags": "ocean trees light boy sunset sky sun moon lighthouse tree eye love portugal nature girl smile clouds cat canon mouth photography glasses photo fishing focus kitten rocks waves peace hand blu obey cap blond moonlight swag moutains supreme vinatge"
       }
            ]
    })
      

  4.   

    其实我想知道http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&amp;format=json&jsoncallback=? 这个是怎么来的,怎么获取得到?其他网站这些要怎么获得
      

  5.   

    别人的网站需要看别人的ajax请求的url或者提供的api
      

  6.   


    那么那些开放平台的api给的地址后面没有callback=?,是要自己加上&callback=?还是直接就把api的地址放在$.getJSON(url,callback)中,再定义callback函数。取得的json数据要先encodeurl再遍历看看里面有什么内容吗?