Link to home
Start Free TrialLog in
Avatar of rpkhare
rpkhareFlag for India

asked on

Retrieve json_encode values in javascript array

I am using following PHP code to store column values and pass to JSON function:

echo json_encode(array($PostedDate.$Places.$Company.$Designation.$ProjectDetails.$DesiredCandidate.$HRName.$HRContact.$Email));

The above thing is returned in a variable called 'data' to JSON function. I want to store the above values in JavsScript array? How to do that?
Avatar of kebabs
kebabs
Flag of Australia image

The point of JSON is to have them stored as JS objects.

So if you have in your JavaScript:

var data = {"a":1, "b":2, "c":3};

You can then access it as such:

data.a

Let me know if that is fine. If you really want a JS array, you can loop over the array instead of running a json_encode() over it and output it with JS array syntax.
Avatar of rpkhare

ASKER

Following code calls the code I mentioned in my original post. Please let me know how to modify it?

				$(document).ready(function(){
					$("#Edit").click(function(){
							$.getJSON("fetchvalues.php?UpdateRecordID=" + $.cookie('UpdateRecordID'),
        					function(data){
							// Data retrieved in concatenated form. So we will break it and store values in array.
							var concatenatedvalues = new Array();
							concatenatedValues = data;
							alert(concatenatedValues.length);
						});
					});
				});

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of rpkhare
rpkhare
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial