tags:

views:

973

answers:

3

There is not a single clear example that explains how to pull json data as simple as possible. I have a valid json and I need to retrieve it with jquery

my json output is as:

{
    "title": "blog entries",
    "items" : [
        {
            "title": "Can Members of the Diaspora Work Effectively at th",
            "date": "8/4/2009 9:42:38 AM"
        },
        {
            "title": "Ashoka Brazil",
            "date": "7/15/2009 8:56:12 AM"
        },
        {
            "title": "Life Spring Hospital",
            "date": "7/15/2009 8:56:12 AM"
        },
        {
            "title": "Pozitron/Endeavor",
            "date": "5/26/2009 8:58:39 PM"
        }
    ]
}

I tried retrieving it with the following but no luck.

 $.getJSON({
     type: "GET",
  data: { PROCESS: "ViewBlog" },
  url: "http://www.pangeaadvisors.org/sep123/blog.cs.asp",
  dataType: "json",
  success: function(json) {
   $(json).find('item').each(function(){
    var title = $(this).find('title').text();
    $('<div class="news_title"></div>').html(title).appendTo('#news_wrap');
   });
  }
 });
A: 

UPDATE

Its failing due to your url having 2 dots in the url

Assuming the request is working (check firebug to see if the request goes out as a script tag & the response comes back) you will need to do

$.each( json.items, function(){

   ...

});

or you can use normal js

for (var i=0; i<json.items.length; i++) {

   ...

}
redsquare
still nothing. see it yourself: http://www0.gsb.columbia.edu/students/organizations/sec/conference2009/blog.htm
Can you use the full jquery version so i can debug. The min version makes it hard!
redsquare
also you dont need to pass the type and datatype for the getJson function
redsquare
thats not the issue however, it fails on a regex with that url
redsquare
replaced jquery with full version. also, removed gettype and type. still not working. Is there a way to fix the problem?
its the two dots in your file name
redsquare
blog.cs.asp ? how can I replace it to blogcs.asp but I cant remove the second one. File wont work?
no idea what stack your on. Why cant you rename it? I dont get you
redsquare
its an asp file??? would bloghtm work?? same thing here.
just call is bla.asp
redsquare
A: 

Try this one

$.getJSON("http://www.pangeaadvisors.org/sep123/blog.cs.asp",{ PROCESS: "ViewBlog" }, function(json) {
                    for (var i = 0; i < json.length; i++) {
                        var title = json[i].Title;
                        $('<div class="news_title"></div>').html(title).appendTo('#news_wrap');
                    }
            });

as redsquare answered you need for or $.each :)

vaske
A: 

I named the file, blogcs.asp. Still nothing is happening.

Efe