Home > Article > Backend Development > Implementation code of asynchronous transmission technology in ThinkAjax_PHP tutorial
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 | ||||
|
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
|
Copy code | ||||