I am storing some key and values in javascript dictionary
var list_of_addressbook_entries = {};
and i am passing that dictionary on a php page
But when i am trying to get the key and value of javascript dict like
$attendee_list = $_POST['dict_of_externals'];
$shared_attendee_list = $_POST['list_of_shared_addressbook_entries'];
$org_attendee_list = $_POST['dict_of_org_users'];
echo json_encode($attendee_list);
return false;
As a response i am getting only "[object Object]"
i just want to know the way how can i extract the values in php ?
in my javascript
for(key in list_of_addressbook_entries)
{
alert("key " + key
+ " has value "
+ list_of_addressbook_entries[key]);
}
is printing the key and values
Updated
var list_of_addressbook_entries_privilege = [];
function showDetails(guest_name){
var user_name = "<?php echo $_SESSION["user_name"]; ?>" ;
var name = prompt("Please use M for moderator and A for attendee", "Type you name here");
if (!name == null && !name== '' || name == 'M' || name == 'A'){
var ahtml='<div id ="div_id_'+guest_name+'" onclick =remove_addressbook_user("'+guest_name+'") class="addr_list" style="display:block; background: none repeat scroll 0% 0% peachpuff;margin-bottom:1px;">'
ahtml = ahtml + '<span>'+guest_name+'</span>'
ahtml = ahtml + '<input type = "hidden" id ="user_id_'+guest_name+'" value = "'+guest_name+'" /></div>'
$(".address_book_list").append(ahtml);
$("#div_id_"+guest_name).hide();
list_of_addressbook_entries[guest_name] = name ;
}
else{
alert("You have entered the worong value ");
return false;
}
$('#dict_of_externals').val(list_of_addressbook_entries);
for(key in list_of_addressbook_entries)
{
alert("key " + key
+ " has value "
+ list_of_addressbook_entries[key]);
}
}
As you can iterate the pair of key values with
for in,list_of_addressbook_entriesis an object.You can’t put an object inside a value property. The value property supports strings only.
Hence JS converts your object to a string, for which the string representation is
[object Object].If you want a string representation of the JSON object you will use
JSON.stringify:if you want to access the JSON object’s properties later, you’ll have to parse the string again with
JSON.parse(orjQuery.parseJSON), hence I’d recommend keeping the object in the memory in case you need to access its property values later.Here’s a small JS library if you need to
JSON.stringifysupport for IE<=7:https://github.com/douglascrockford/JSON-js