TP + PjaxDemo implements the method of refreshing URL changes

Source: Internet
Author: User
Provides various official and user-released code examples. For more information, see TP3.1.3 + Pjax Demo.
You can view the principles and usage of Pjax on the following website.
Welefen version: https://github.com/welefen/pjax
Defunkt version: https://github.com/defunkt/jquery-pjax [This is the Demo]

Browser (HTML5): http://caniuse.com/#search=pushstate supporting Pjax functionality

TP + Pjax Demo implementation method:
./Lib/Common. Action. class. php [temporarily enable the template layout (true); for usage, see http://www.thinkphp1.cn/info/183.htmlthird formula] Class CommonAction extends Action {
Protected function render ($ data ){
$ This-> assign ('data', $ data); // The Controller transmits the value to the template.

If (array_key_exists ('HTTP _ X_PJAX ', $ _ SERVER) & $ _ SERVER ['HTTP _ X_PJAX']) {
$ This-> display ('', 'pjax/'); // the browser supports the pjax function to directly render the output page. Bug fix: compatible with non-debug mode
} Else {
Layout (true); // enable the Template
$ This-> display (); // the browser does not support the Pjax function or F5 to refresh the page. Use the default link Response Mechanism (load template)
}
}
}
./Lib/IndexAction. class. php (inherited from CommonAction) Class IndexAction extends CommonAction {
Public function index (){
$ Data ['name'] = 'thinkphp + Pjax demo ';
$ This-> render ($ data );
}

Public function about (){
$ Data ['name'] = 'test parameter passing. ';
$ This-> render ($ data );
}
}
./TPL/layout.html (Pjax deployment in the template)

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.