ThinkPHP3.1 new features for Ajax support More perfect _php instance

Source: Internet
Author: User

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.

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.