ThinkPHP3.1 version of Ajax support more complete, the specific performance in:
1. How to judge Ajax improvements
You can now use the constant Is_ajax directly to determine whether the Ajax way request is used to replace the Isajax method of the previous action class, which can be judged in any code. The error and success method of the action class is built to support automatic judgment support for Ajax.
2.ajaxReturn Method Perfect
The original Ajaxreturn method can only return the fixed structure of the data, including the information of data, status and info index, if you need to extend additional return data information, only through the Ajaxassign method, The ThinkPHP3.1 version improves the Ajaxreturn method itself and enables better support for AJAX data extensions, such as:
$data [' status '] = 1;
$data [' info '] = ' return information ';
$data [' data '] = ' return ';
$data [' url '] = ' URL address ';
$this->ajaxreturn ($data);
An array of data values can be defined arbitrarily.
The improved Ajaxreturn method is also compatible with previous wording, such as:
$this->ajaxreturn ($data, ' info ', 1);
The system automatically incorporates info and 12 parameters into the $data array, equivalent to the assignment
$data [' info '] = ' info ';
$data [' status '] = 1;
$data [' data '] = $data;
$this->ajaxreturn ($data);
However, this usage is no longer recommended.
3.success and Error methods perfect for AJAX support
In the case of Ajax, the success and error methods of the action class are improved, and the parameters of the two methods are converted to the info, status, and URL parameters of the data for the Ajaxreturn method. You can also support passing in other parameters, and there are two ways to support Ajax transfer values. Take the success method as an example, the first way is to directly pass in AJAX data
$data [' code '] =;
$data [' name '] = ' thinkphp ';
$this->success (' success message ', ' Jump address ', $data);
or adopt
$this->assign (' Code ');
$this->assign (' name ', ' thinkphp ');
$this->success (' success message ', ' Jump address ');
The AJAX data information that is eventually returned to the client is an array, including name, code, info, status, and URL.