I need some help with JSON and jquery.
I developing application with dhtmlx scheduler. I want to create dhtmlx sections dynamically.
I generating json_encoded string using php json_encode function given in following
["{key:23, label:'T23 (34)'}","{key:24, label:'T24 (34)'}","{key:26, label:'T26 (26)'}","{key:35, label:'T35 (25)'}"]
Ajax call function for this
$.ajax({
url:"updatetablestr.php",
type:"get",
data:{id:id},
dataType: 'json',
beforeSend:function(){},
success:function(q)
{
var JSONString = JSON.stringify(q);
var output=JSONString.replace(/\"/g,"");
scheduler.updateCollection("MyList",output);
}
})
PHP function is,
$resarray=json_encode($array);
echo preg_replace('/"([a-zA-Z]+[a-zA-Z0-9_]*)":/', '$1:', $resarray);
i removed first and last quotes using jquery
var JSONString = JSON.stringify(q);
var output =JSONString.replace(/\"/g,"");
after this jquery code i could get my output
[{key:23, label:'T23 (34)'}","{key:24, label:'T24 (34)'}","{key:26, label:'T26 (26)'}","{key:35, label:'T35 (25)'}]
This output is what i need. when i use static code like
var output= [{key:23, label:'T23 (34)'}","{key:24, label:'T24 (34)'}","{key:26, label:'T26 (26)'}","{key:35, label:'T35 (25)'}]
is working . When i implement dynamically which generated php , JSON.stringify is not working.. that time its showing the following error
scheduler.updateCollection("MyList",output);
"Uncaught TypeError: Function.prototype.apply: Arguments list has wrong type" in dhtmlxschduler.js
While statically working with same string why it's not working when dynamically generated using php and jquery..