rpkhare
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($PostedD ate.$Place s.$Company .$Designat ion.$Proje ctDetails. $DesiredCa ndidate.$H RName.$HRC ontact.$Em ail));
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?
echo json_encode(array($PostedD
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?
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);
});
});
});
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.