This is closely related to the problem I am having.  And the tip about
console.log was great.

However:

 I have an object created using json_encode and via the console.log
entry as suggested, I can see that it is correct.   I have a backend
program that I'm wanting to pass this object to, so that it can do a
json_decode and then process that data.   When I try to pass the
object to it, using:
  $.post(prog,{data:data},function(){},"json");   the result is that
the backend program receives a $_POST['data'] that looks like:
  [object Object] instead of the json_encoded string.

I'm pulling my hair out on this..



On Oct 27, 12:14�am, jfrymann <[EMAIL PROTECTED]> wrote:
> Thank you, that was exactly what I needed to know. �Got it all
> working. �Also, the tip about looking at the contents in Firebug is
> very useful. �I have also just started using Firebug and am starting
> to discover all its useful features.
>
> On Oct 26, 9:37�am, "Michael Geary" <[EMAIL PROTECTED]> wrote:
>
>
>
> > The example PHP code would actually echo a series of JSON objects all
> > concatenated together, each one having two properties named file and byline.
> > You wouldn't get any kind of valid JSON out of this. It would look something
> > like this (probably without the whitespace):
>
> > { "file": something, "byline": something }
> > { "file": something, "byline": something }
> > { "file": something, "byline": something }
> > { "file": something, "byline": something }
>
> > json_encode looks at an array you give it and decides whether to render it
> > as a JSON array or a JSON object depending on whether it has named
> > properties or only numeric indices.
>
> > jfryman, if you want to return an *array* of these objects, then make an
> > array of them. � � � � � � � � Perhaps:
>
> > $array = array();
> > while( $row = mysql_fetch_array($result) ) {
> > �� � � �$array[] = array("file"=>$row['name'],"byline"=> $row['byline']);}
>
> > echo json_encode($array);
>
> > Then, in your jQuery code, replace this:
>
> > alert( data );
>
> > with:
>
> > console.log( data );
>
> > And load your page in Firefox with Firebug.
>
> > After the data downloads, you should have an entry in the Firebug console.
> > Click on that and you can see the details of the array and drill down into
> > its elements.
>
> > -Mike
>
> > > From: Ariel Flesler
>
> > > If you are indeed returning an array from PHP, then the
> > > received JSON should be a js array.
> > > Got this online ?
> > > > From: jfrymann
> > > > Hi,
> > > > � I have just started using jQuery and am trying to get
> > > > data back from a mysql database in json format. �I am
> > > > using PHP to query the database and returning it with
> > > > the json_encode method. �(Basically I am following
> > > > the example in the documentation
> > > >http://docs.jquery.com/Ajax/jQuery.post#urldatacallbacktype
>
> > > > The problem I am having is that the example only returns one json
> > > > object rather than an array of them and I'm not sure how to
> > > > modify the calls to either the php encode json or how to access the
> > > > data when it is returned through jquery.
>
> > > > At the moment my php looks like this:
>
> > > > while($row = mysql_fetch_array($result)) {
> > > > � � � � echo json_encode(array("file"=>$row['name'],"byline"=>
> > > > $row['byline']));
>
> > > > }
>
> > > > and the jQuery:
>
> > > > $.post("getimages.php", { location: opt_choice, curr_img: img_cnt,
> > > > limit: img_lim },
> > > > � � � � � � � � � � � � � � � � � � � � � function(data){
> > > > � � � � � � � � � � � � � � � � � � � � � � alert(data);
> > > > � � � � � � � � � � � � � � � � � � � � � }, "json");
>
> > > > How can I set it up to access multiple objects?
> > > > Thanks for the help!- Hide quoted text -
>
> - Show quoted text -

Reply via email to