File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes problem in json/ajax Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "problem in json/ajax" Watch "problem in json/ajax" New topic
Author

problem in json/ajax

Daniel Cipriano
Greenhorn

Joined: Feb 02, 2011
Posts: 14
i have this code

Code:


and a php

PHP Code:


the result is something like [{"valor1":"20"},{"valor2":"50"}]

i don't know why the ajax only works without [] like:

{"valor1":"20"},{"valor2":"50"}

what is the problem? and how i can solve that? if i change $arr[] to $arr only show the last value of the table

thanks
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
This is not a JSON object, that is an array.


If you want to pass it back as a JSON object, than:



Than with the response you just do

json.values to get the array.

Eric

Daniel Cipriano
Greenhorn

Joined: Feb 02, 2011
Posts: 14
this solve my problem



thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60058
    
  65

Yeah, you've got to treat the data the way that it is formatted. If an array is returned, you need to treat it like an array.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in json/ajax
 
Similar Threads
Pass JSON object from server to jQuery and loop on the object
do not get JSON data back (using JSONPlugin)
Encode java, decode javascript
Using a Variable with AJAX
JSON JQuery Grid Not getting value in JSP