Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-06-2012, 12:54 AM   PM User | #1
coding_begins
Regular Coder

 
Join Date: Aug 2011
Posts: 134
Thanks: 20
Thanked 0 Times in 0 Posts
coding_begins is an unknown quantity at this point
return json output without square brakets

I am returning the following through JSON:

Code:
$this->view->lead_query=$lead_query->fetchALL();
header('OK', true, 200);
header('Content-type: application/json');
echo json_encode($this->view->lead_query);
I am getting the results in this format:
[{"client_name":"Steve Harris","state":"TX"}]

Now if the above output was displayed without the square brackets [] I can populate the values in my form correctly.
Is there a way i can return the output without the square brackets?
coding_begins is offline   Reply With Quote
Old 02-06-2012, 01:32 AM   PM User | #2
coding_begins
Regular Coder

 
Join Date: Aug 2011
Posts: 134
Thanks: 20
Thanked 0 Times in 0 Posts
coding_begins is an unknown quantity at this point
PHP Code:
str_replace( array( '['']'), ''json_encode($this->view->lead_query)) 
the above worked for me
coding_begins is offline   Reply With Quote
Old 02-06-2012, 07:24 AM   PM User | #3
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
Otherwise you could as well process the returned JSON in Javascript as an array rather than as an object.

You possibly tried
Code:
myobject.client_name
and you can do this instead
Code:
myobject[0].client_name
devnull69 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:30 AM.


Advertisement
Log in to turn off these ads.