LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-10-2012, 08:29 PM   #1
secretlydead
Member
 
Registered: Sep 2003
Location: Qingdao, China
Distribution: mandriva, slack, red flag
Posts: 249

Rep: Reputation: 31
echo javascript json array


i have a script that's retrieving a json string through ajax.

if i alert(data), i get:
{"account_id":805267,"customer_id":882315,"account_name":"","account_number":"6011xxxxxxxxxxx0000"," enabled":false,"type":"2","bank_name":"","cc_name":"","expiration":"1215","is_savings":false,"date_a dded":"20120210","date_modified":"20120210"}
in a popup window...

but if i
alert(data.account_number), i get
"undefined" in a popup window.

what am i doing wrong?
 
Old 02-10-2012, 09:06 PM   #2
secretlydead
Member
 
Registered: Sep 2003
Location: Qingdao, China
Distribution: mandriva, slack, red flag
Posts: 249

Original Poster
Rep: Reputation: 31
BAH!!! (need to be reviewing my javascript books and notes everyday)

alert( $.parseJSON(data).account_number ); does it.
 
Old 02-11-2012, 06:20 AM   #3
audriusk
Member
 
Registered: Mar 2011
Location: Klaipėda, Lithuania
Distribution: Slackware
Posts: 352

Rep: Reputation: 198Reputation: 198
You don't need to use $.parseJSON() in AJAX call. Instead you should use $.getJSON() or set dataType to 'json' for $.ajax(). This way jQuery will parse JSON data for you, and you'll be able to use it right away.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
What is Json and jQuery and how are they related to Javascript? Romanus81 Programming 1 08-13-2009 09:35 PM
Javascript - trouble using array with getElementById fcdev Programming 2 06-17-2009 10:36 PM
PHP and JavaScript: problem with echo()-ing unwanted line breaks Robhogg Programming 3 02-12-2007 07:52 AM
javascript calls to embedded echo'd php forms xemous Programming 1 08-21-2005 06:29 AM
returning an array from a function.. javascript sonesay Programming 1 06-07-2004 05:28 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration