When you return with Eval, you don't always get the value, ask why
Source: Internet
Author: User
When you return with Eval, you don't always get the value.
-------------------------------------------------
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.
------to solve the idea----------------------
Make sure MSG is JSON formatted data
------to solve the idea----------------------
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);
/// $dataaThe type 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.
}
}
------to solve the idea----------------------
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.
------to solve the idea----------------------
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 content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.