[jQuery] getJSON - how do you make it work?

2008-08-18 Thread Jon Sidnell

Hi

I'm trying to get some JSON content using the $.getJSON function, but
it just won't work!!

I started out using ASP.NET to generate a load of JSON, but decided to
create a simple text file with a JSON string in it instead.

Here's my JavaScript:

$.getJSON(/test.txt, function(data) {
alert(I got the stuff);
});

$(#msg).ajaxError(function(event, request, settings, error) {
$(this).append(p + error + /p);
});

And my test.txt file contains:

{ offer: {
id: 2,
title: animals could talk,
image: _blank.gif
}
}

Is there anything really obvious I'm doing wrong?

Thanks
Jon


[jQuery] Re: getJSON - how do you make it work?

2008-08-18 Thread Jon Sidnell

I finally worked it out! Apparently, IIS reports a 404 for file
extensions it doesn't recognise as safe, so *.json file was a big no-
no.

Soon as I changed it to the .txt file mentioned above (must've posted
that as an idea before actually trying it in my code - oops!) it all
worked.

Then moving into the proper project, turns out the JSON being
generated by ASP.NET was invalid (the JSON validator at JSONlint.com
was my friend for that one). It's all working tickety-boo now :)

Thanks all
Jon

On Aug 18, 2:08 pm, Ryura [EMAIL PROTECTED] wrote:
 Is it actually accessing the file correctly? I'd say provide a test
 case or check yourself with Firebug.

 On Aug 18, 6:00 am, Jon Sidnell [EMAIL PROTECTED] wrote:

  Hi

  I'm trying to get some JSON content using the $.getJSON function, but
  it just won't work!!

  I started out using ASP.NET to generate a load of JSON, but decided to
  create a simple text file with a JSON string in it instead.

  Here's my JavaScript:

          $.getJSON(/test.txt, function(data) {
                  alert(I got the stuff);
          });

          $(#msg).ajaxError(function(event, request, settings, error) {
                  $(this).append(p + error + /p);
          });

  And my test.txt file contains:

          { offer: {
                  id: 2,
                  title: animals could talk,
                  image: _blank.gif
                  }
          }

  Is there anything really obvious I'm doing wrong?

  Thanks
  Jon