Original application code of ajax in joomla

Source: Internet
Author: User
Tags mootools

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.