jquery ajax: newbie question
A file called test contai开发者_如何转开发ning the following line:
[{"foo":"abc","bar":"01"},{"foo":"def","bar":"02"}]
jquery ajax:
$.ajax({ url: "test", success: function(data) {....
Stupid question maybe, but shouldnt i be able to get the values in the function with something like data.foo
? Never used ajax before as you might have figured out :)
In your specific case, you can't exactly call data.foo
because your data
object is actually an array of objects, so you would access its properties with data[0].foo
, data[1].foo
and so on.
Yes, you would be able, the [{"foo":"abc","bar":"01"},{"foo":"def","bar":"02"}]
data structure is called json
and jQuery parses it without problem, it even has a specific method for json jQuery.getJSON. See examples here:
http://pinoytech.org/blog/post/How-to-Use-JSON-with-jQuery-AJAX
http://viralpatel.net/blogs/2009/04/jquery-ajax-tutorial-example-ajax-jquery-development.html
精彩评论