Home Backend Development PHP Tutorial Implementation code of asynchronous transmission technology in ThinkAjax_PHP tutorial

Implementation code of asynchronous transmission technology in ThinkAjax_PHP tutorial

Jul 13, 2016 pm 04:59 PM
code transmission use exist Example accomplish asynchronous technology new technology

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 of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to implement dual WeChat login on Huawei mobile phones? How to implement dual WeChat login on Huawei mobile phones? Mar 24, 2024 am 11:27 AM

How to implement dual WeChat login on Huawei mobile phones? With the rise of social media, WeChat has become one of the indispensable communication tools in people's daily lives. However, many people may encounter a problem: logging into multiple WeChat accounts at the same time on the same mobile phone. For Huawei mobile phone users, it is not difficult to achieve dual WeChat login. This article will introduce how to achieve dual WeChat login on Huawei mobile phones. First of all, the EMUI system that comes with Huawei mobile phones provides a very convenient function - dual application opening. Through the application dual opening function, users can simultaneously

DualBEV: significantly surpassing BEVFormer and BEVDet4D, open the book! DualBEV: significantly surpassing BEVFormer and BEVDet4D, open the book! Mar 21, 2024 pm 05:21 PM

This paper explores the problem of accurately detecting objects from different viewing angles (such as perspective and bird's-eye view) in autonomous driving, especially how to effectively transform features from perspective (PV) to bird's-eye view (BEV) space. Transformation is implemented via the Visual Transformation (VT) module. Existing methods are broadly divided into two strategies: 2D to 3D and 3D to 2D conversion. 2D-to-3D methods improve dense 2D features by predicting depth probabilities, but the inherent uncertainty of depth predictions, especially in distant regions, may introduce inaccuracies. While 3D to 2D methods usually use 3D queries to sample 2D features and learn the attention weights of the correspondence between 3D and 2D features through a Transformer, which increases the computational and deployment time.

PHP Programming Guide: Methods to Implement Fibonacci Sequence PHP Programming Guide: Methods to Implement Fibonacci Sequence Mar 20, 2024 pm 04:54 PM

The programming language PHP is a powerful tool for web development, capable of supporting a variety of different programming logics and algorithms. Among them, implementing the Fibonacci sequence is a common and classic programming problem. In this article, we will introduce how to use the PHP programming language to implement the Fibonacci sequence, and attach specific code examples. The Fibonacci sequence is a mathematical sequence defined as follows: the first and second elements of the sequence are 1, and starting from the third element, the value of each element is equal to the sum of the previous two elements. The first few elements of the sequence

How to implement the WeChat clone function on Huawei mobile phones How to implement the WeChat clone function on Huawei mobile phones Mar 24, 2024 pm 06:03 PM

How to implement the WeChat clone function on Huawei mobile phones With the popularity of social software and people's increasing emphasis on privacy and security, the WeChat clone function has gradually become the focus of people's attention. The WeChat clone function can help users log in to multiple WeChat accounts on the same mobile phone at the same time, making it easier to manage and use. It is not difficult to implement the WeChat clone function on Huawei mobile phones. You only need to follow the following steps. Step 1: Make sure that the mobile phone system version and WeChat version meet the requirements. First, make sure that your Huawei mobile phone system version has been updated to the latest version, as well as the WeChat App.

Master how Golang enables game development possibilities Master how Golang enables game development possibilities Mar 16, 2024 pm 12:57 PM

In today's software development field, Golang (Go language), as an efficient, concise and highly concurrency programming language, is increasingly favored by developers. Its rich standard library and efficient concurrency features make it a high-profile choice in the field of game development. This article will explore how to use Golang for game development and demonstrate its powerful possibilities through specific code examples. 1. Golang’s advantages in game development. As a statically typed language, Golang is used in building large-scale game systems.

PHP Game Requirements Implementation Guide PHP Game Requirements Implementation Guide Mar 11, 2024 am 08:45 AM

PHP Game Requirements Implementation Guide With the popularity and development of the Internet, the web game market is becoming more and more popular. Many developers hope to use the PHP language to develop their own web games, and implementing game requirements is a key step. This article will introduce how to use PHP language to implement common game requirements and provide specific code examples. 1. Create game characters In web games, game characters are a very important element. We need to define the attributes of the game character, such as name, level, experience value, etc., and provide methods to operate these

Create and run Linux ".a" files Create and run Linux ".a" files Mar 20, 2024 pm 04:46 PM

Working with files in the Linux operating system requires the use of various commands and techniques that enable developers to efficiently create and execute files, code, programs, scripts, and other things. In the Linux environment, files with the extension &quot;.a&quot; have great importance as static libraries. These libraries play an important role in software development, allowing developers to efficiently manage and share common functionality across multiple programs. For effective software development in a Linux environment, it is crucial to understand how to create and run &quot;.a&quot; files. This article will introduce how to comprehensively install and configure the Linux &quot;.a&quot; file. Let's explore the definition, purpose, structure, and methods of creating and executing the Linux &quot;.a&quot; file. What is L

How to use Copilot to generate code How to use Copilot to generate code Mar 23, 2024 am 10:41 AM

As a programmer, I get excited about tools that simplify the coding experience. With the help of artificial intelligence tools, we can generate demo code and make necessary modifications as per the requirement. The newly introduced Copilot tool in Visual Studio Code allows us to create AI-generated code with natural language chat interactions. By explaining functionality, we can better understand the meaning of existing code. How to use Copilot to generate code? To get started, we first need to get the latest PowerPlatformTools extension. To achieve this, you need to go to the extension page, search for &quot;PowerPlatformTool&quot; and click the Install button

See all articles