The ThinkPHP3.1 version of AJAX support is more complete, the specific performance in:
1. Determine the Ajax way to improve
It is now possible to use constant is_ajax to determine whether an AJAX request is used to replace the Isajax method of the previous action class, and the advantage is that it can be judged in any code. And the action class's error and success method built-in support for Ajax auto-judgment support.
2.ajaxReturn Method Perfect
The original Ajaxreturn method can only return the fixed structure of the data, including information, status and info index, if you need to extend the additional return data information, only through the Ajaxassign method, The ThinkPHP3.1 version, however, has improved the Ajaxreturn method itself, which provides 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);
The data value array can be defined arbitrarily.
The improved Ajaxreturn method is also compatible with previous formulations, such as:
$this->ajaxreturn ($data, ' info ', 1);
The system automatically merges the info and 12 parameters into the $data array, which is equivalent to assigning a value
$data [' info '] = ' info '; $data [' status '] = 1; $data [' data '] = $data; $this->ajaxreturn ($data);
However, this usage is no longer recommended for use.
3.success and error method perfect for AJAX support
In the case of Ajax, the action class's success and error methods are improved, and the parameters of the two methods are converted to the info, status, and URL parameters of the Ajaxreturn method's data. You can also support passing in other parameters, and there are two ways to support the value of Ajax. In the case of the success method, the first way is to pass in the AJAX data directly
$data [' code '] = $, $data [' name '] = ' thinkphp '; $this->success (' successful message ', ' Jump address ', $data);
or using
$this->assign (' Code '), $this->assign (' name ', ' thinkphp '), $this->success (' success message ', ' Jump address ');
The AJAX data information that is ultimately returned to the client is an array, including name, code, info, status, and URL.
http://www.bkjia.com/PHPjc/825444.html www.bkjia.com true http://www.bkjia.com/PHPjc/825444.html techarticle ThinkPHP3.1 version of AJAX support more complete, the specific performance in: 1. Determine the Ajax way to improve now you can directly use the constant Is_ajax to determine whether the AJAX request, to replace the previous ...