The JSON notation simply means that, in your case, 'data' is a
javascript object available within the callback function, and is
accessible using standard javascript methods.

So, if the POST were to return the JSON as ...

{ numOfResults : 2
, term : "kiss"
, definition : [ "A (tender) touching of the lips"
                  , "Acronym : Keep It Simple Stupid" ]
}

then that object is accessible as 'data', and your callback function
could (purely as an example!) ...

function(data){
  if(data){ // just in case the called program had a problem
    // let's assume that we have a div with an id of 'results'...
    var res = $('#results').empty();
    // you probably should have some sort of error handler
    // for cases where the numOfResults is zero ...
    if(data.numOfResults == 0){
      // display 'None Found' or something...
      res.append('<div class="noneFound">None Found!</div>');
    }else{
      // put 'term' and 'numOfResults' in a header...
      res.append('<h2>Definition(s) of "' + data.term + '" (' +
data.numOfResults + ')</h2>');
      // add a numbered div for each definition (definition being an
array)...
      $.each(data.definition, function(i, v){
          res.append('<div>' + (i+1) + '.&nbsp;' + v + '</div>');
        });
    } // end of else
  } // end of if(data)
} // end of callback

HTH

(if you're unsure of the structure of the returned JSON, use Firebug,
break at the first line of the callback function, and look at the
variable 'data').


On Oct 31, 5:24 am, james_027 <[EMAIL PROTECTED]> wrote:
> hi,
>
> I very new with json ( you may say that I still really don't
> understand it quite well), how do I use the json object that is return
> from the $.post in its callback argument?
>
> $.post('/ap/item/code/edit/',
>                 values,
>                 function (data){
>                         //how to access the json object from the data?
>                 }
>         );
>
> the data is json object in particular is a dictionary
>
> thanks
> james

Reply via email to