-------------------------------------------------
Public Function Ajax () {
Var_dump ($_post);d ie;
$data =array ();
$Model = new Model ();
$data [' content ']=$_post[' content '];
$data [' Time ']=time ();
$data [' Timee ']=date (' y-m-d h:i:s ', Time ());
$data [' sender ']= ' AAA ';
$dd =m (msg)->data ($data)->add ();
if ($DD) {
$dataa =m (' msg ')->order (' id desc ')->limit (' 5 ')->select ();//This is the one where 5 data records can be removed.
$this->ajaxreturn ($DATAA);
}
}
var dat=eval ("(" + msg + ")");//Use this sentence, the following will be executed, excuse me for what? I made it with thinkphp3.1.2.
Reply to discussion (solution)
Make sure MSG is JSON formatted data
Alert (msg) look at
Alert (msg) look at
Popup to display [object Object],[object object],[object object],[object Object],[object Object]
Public Function Ajax () {
Var_dump ($_post);d ie;
$data =array ();
$Model = new Model ();
$data [' content ']=$_post[' content '];
$data [' Time ']=time ();
$data [' Timee ']=date (' y-m-d h:i:s ', Time ());
$data [' sender ']= ' AAA ';
$dd =m (msg)->data ($data)->add ();
if ($DD) {
$dataa =m (' msg ')->order (' id desc ')->limit (' 5 ')->select ();//This is the one where 5 data records can be removed.
$this->ajaxreturn ($DATAA);
The type of $DATAA is already an array. Your front end can be used directly, alert (MSG. Your Data key value), no more eval.
or convert the array to a JSON string
$this->ajaxreturn (Json_encode ($DATAA));//This reurn is a JSON string, your front end to eval or other parsing JSON method parsing.
}
}
You are using the JSON conversion of thinkphp then you specify the type of JSON parameter that is returned when you post in jquery
If alert (msg)
Popup to display [object Object],[object object],[object object],[object Object],[object Object]
It means that MSG is already a parsed JS array. Obviously you do not provide the real code, because if there is no JSON parameter, $.post is not self-parsing
Since MSG has been parsed,
var dat=eval ("(" + msg + ")");
It's just wrong.
The data you returned is already JSON and does not need to be eval.
var dat=eval ("(" + msg + ")");
Switch
var dat=msg;
You can do it.
The function should be appended with a ' JSON ' to declare the JSON format returned