Today, I am going to talk about how to implement ajax using the mootools javascript library that comes with joomla. Because it is a built-in library, you don't have to worry about jquery. How can we implement it, first, create an ajax get button, which is generally used in component editing. Therefore, the file is generally used in views \ your view \ tmpl \ default. php:
Copy codeThe Code is as follows:
<Input type = "button" id = "ajaxButton" value = "Get mode"/>
<Div id = "someID"> </div>
$ Doc = & JFactory: getDocument ();
$ Script = <SCRIPT
Window. addEvent ('domainready', function (){
$ ('Ajaxbutton'). addEvent ('click', function (){
New Ajax (
'Index. php? Option = com_category & controller = category & task = aj & format = ajax ',
{
Method: 'get ',
Update: 'someid'
}
). Request ();
});
});
SCRIPT;
The input line is a button to get ajax, followed by the div layer that shows the returned data. The following is the code for using ajax mootools. To put it simply, add js to the document head using the getDocument class method. Note that $ represents the mootools class library. The URL parameters in ajax are component name, controller name, and execution method aj first, this is written in the Controller. It is the method executed after clicking the button. You need to write the returned data, and finally the returned data type. ajax is required here. Otherwise, the entire document will be returned, here we only need to return the Data Part Of The aj method. there are two parameters: get is the way to get data, someID is the bound returned data display id, which is required.
Ajax is not required, but sometimes it has to be used. If it is used in the original ecology, I want to load it very quickly, and I have never used the mootools library, but it is just a fake image, after all, we provide a method to implement ajax. To implement the POST method, you only need to add the corresponding form element. I will not talk about it here, because not many are used. let's just talk about it here. We will not provide an example. If you need to edit the form element, you can try the code very short. Just copy it!