ThinkPHP3.1 new features for AJAX support more complete _php tutorials

Source: Internet
Author: User
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 ...

  • 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.