I am creating one website in php. and i am using jquery ajax to pass data from one page to another. and that is general process for all pages.
my javascript function is :
function add_data()
{
var searchinOn = mainObjectAddForm['available_add_fields'].split(",");
var whereOn="{";
var where = "";
for (i=0;i<searchinOn.length;i++)
{
var keyValue= searchinOn[i];
where+=getAddData(mainObjectAddForm[keyValue]['name'],mainObjectAddForm[keyValue]['text'],mainObjectAddForm[keyValue]['datatype'],mainObjectAddForm[keyValue]['data'],keyValue)
}
whereOn+= where.substring(0,where.length-1)+"}";
$.ajax({
type:'POST',
data:whereOn,
url:siteurl + "add/",
dataType:'json',
success:function(data)
{
}
});
}
function getAddData(name,text,datatype,data,keyValue)
{
var control="";
var value1="";
var value2="";
switch(datatype)
{
case "text":
control += "'"+name+"':'"+trim($('#add_form #'+name).val())+"'";
break;
case "password":
control += "'"+name+"':'"+trim($('#add_form #'+name).val())+"'";
break;
case "label":
control += "'"+name+"':'"+trim($('#add_form #'+name).val())+"'";
break;
case "textarea":
control += "'"+name+"':'"+trim($('#add_form #'+name).val())+"'";
break;
}
if (trim(control)=="") return "";
else return control + ",";
}
but on php page i am not getting all values. Its coming as one string in post variable.
like
[{'field1':'abc','field2':'pqr','field3':'xyz'}] =>
but i want like this :
Array
{
[field1] => abc
[field2] => pqr
[field3] => xyz
}
and i know the problem that the problem is the ajax data is passing as one string because the '{' and '}' are in whereOn string. but if i add that in ajax call than also its same problem.
can anyone help me to solve it ?