How to implement asynchronous transmission technology using ThinkAjax built in ThinkPHP_PHP Tutorial

WBOY
Release: 2016-07-21 15:22:43
Original
1183 people have browsed it

Preparation work:
① First of all, you must be able to use the ThinkPHP framework
② It is best to have some basics of ajax (you can check out Xiaofei's other blog post: Ajax real-time verification of whether "user name/email, etc." already exists )
③ 4 js documents (click here to download for free)

Paste the source code first:

Copy the code The code is as follows :















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 used 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 in total :
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 ajax The parameter string in the send method in means that the past data is to be submitted. This parameter is only used to pass values ​​in the post method
Parameter response: a custom callback function. If the callback function is defined, the server will process the submitted data. After receiving the data, the processed data will be handed over 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 the processed data Where to display (or output), for example: I assign this parameter to: checkbox, which means that the processed data will be output in the label with id="checkbox"
Source code of the checktitle method under the current module :
Copy code The code is as follows:

class IndexAction extends Action
{
//Homepage
public function index(){
$this->display();
}
// Check whether the title is available
public function checkTitle()
{
if(!empty($_POST['title']))
{
$Form = D("Form");
if($Form->getByTitle($_POST[' title']))
{
$this->error('title already exists');
}
else
{
$this->success('title Can be used!');
}
}
else
{
$this->error('Title cannot be empty...');
}
}
}
?>

Article author: WEB Development_Xiao Fei

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324640.htmlTechArticlePreparation work: ① First, you must be able to use the ThinkPHP framework ② It is best to have some basic ajax (you can check out the small Another blog post from Fei: Ajax real-time verification whether "user name/email, etc." has been...
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!