Home  >  Article  >  Backend Development  >  Implementation code of asynchronous transmission technology in ThinkAjax_PHP tutorial

Implementation code of asynchronous transmission technology in ThinkAjax_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 16:59:51753browse

This example introduces the use of the refreshless technology in thinkajax to implement asynchronous transmission. Friends in need can refer to it.

ThinkPHP’s official documentation does not give out how to use ThinkAjax, which makes it inconvenient for many beginners to use. I learned this today and encountered many problems. I will take the time to study it in depth and make study notes. I hope it can help beginners. Helpful.

The code is as follows Copy code
 代码如下 复制代码

 

    

    

       

       

       

    

                 

     

 

标题:

       

                 

       

       

       

     
Title:                                                                                                                                                                                                  

Code explanation:

Add an onclick event for the "Check" button. When the button is clicked, call the checktitle() function
In the checktitle function, we only use the member method send
in the ThinkAjax object send:function(url,pars,response,target,tips,effect){……}

It can be seen that the ThinkAjax.send method has 6 parameters:

Parameter url: Indicates which method to submit the data transmitted from the client browser to the server for processing. I submit it here to the "checktitle method under the current module" for processing

Parameter pars: equivalent to the parameter string in the send method in ajax, indicating that past data is to be submitted. This parameter is only used to transfer values ​​in post mode

Parameter response: Custom callback function. If the callback function is defined, after the server processes the submitted data, it will hand the processed data to the callback function for processing. The callback function has two parameters: ①data②status Parameter data: Assign the data processed by the server to data Parameter status: Indicates the status information after processing, 1 means success, 0 means failure

Parameter target: Indicates where the processed data will be displayed (or output). For example: I assign this parameter to: checkbox, which means that the processed data will be output at the label with id="checkbox".

Source code of the checktitle method under the current module:

The code is as follows
 代码如下 复制代码

class IndexAction extends Action
{
// 首页
public function index(){
$this->display();
       }
       // 检查标题是否可用
       public function checkTitle()
       {
              if(!empty($_POST['title']))
                     {
                     $Form     =     D("Form");
                     if($Form->getByTitle($_POST['title']))
                     {
                            $this->error('标题已经存在');
                     }
                     else
                     {
                            $this->success('标题可以使用!');
                     }
              }
              else
              {
                     $this->error('标题不能为空...');
              }
       }
}
?>

Copy code
class IndexAction extends Action<🎜> {<🎜> // Home<🎜> Public function index(){<🎜> $this->display(); } // Check if the title is available        public function checkTitle()           { If(!empty($_POST['title']))                                                              {                             $Form                                                                                                                             If($Form->getByTitle($_POST['title']))                                                              { $this->error('Title already exists');                     }                                                  else                                                              { $this->success('Title is available!');                     }               }               else                   { $ This- & gt; error ('' title cannot be empty ... ');               } } } ?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631296.htmlTechArticleThis example introduces the use of refreshless technology in thinkajax to implement asynchronous transmission. Friends in need can refer to it. . The official documentation of ThinkPHP does not give how to use ThinkAjax,...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn