Hot answers tagged

48 votes
Accepted

What is the proper way to make an AJAX call in component?

PLEASE NOTE THAT THIS ANSWER is already a few years old and was not updated. Feel free to edit / comment if you think something is no longer exact. Abstract There is almost no really official way ...
user avatar
20 votes

What is the proper way to make an AJAX call in component?

This is a late answer for this very well answered question, but I wanted to add this cut-to-the-chase solution for those that just need a simple way to get to their components's data with an AJAX call....
user avatar
  • 7,665
11 votes

What is the proper way to make an AJAX call in component?

Valentin answer is good but is a bit overly complex if all you need to do is add 1 or 2 ajax calls to a component that is already built. It's perfectly possible to get away with not making separate ...
user avatar
  • 887
10 votes
Accepted

How to pass variables via $.ajax to a controller

You should use Joomla's JInput class https://docs.joomla.org/Retrieving_request_data_using_JInput e.g. public function add() { // Get Joomla's input object: $input = JFactory::getApplication()-&...
user avatar
  • 1,006
9 votes
Accepted

Trash Joomla Article in frontend

First of all you need to pass article ID with your request. Then you can use JTable class to update the state: public function onAjaxDeletearticle() { // Get id from the request $id = ...
user avatar
  • 4,045
7 votes

What is the proper way to make an AJAX call in component?

Valentin's answer is good. I prefer a json controller that handles the encoding and error handling for this I created a json base class: class itrControllerJson extends JControllerLegacy { /** @...
user avatar
7 votes
Accepted

What is the recommended way to structure a Joomla 3 custom component view using angularJS?

According to my experience: JSON views: I have created components based FoF automatic JSON rendering https://github.com/akeeba/fof In this way, it is straightforward to load /get queries. In spite of ...
user avatar
  • 7,415
6 votes
Accepted

How to render System Message from AJAX call

All the things mentioned by @Bakual are correct but I notice that you are just passing the result.message to alert and given that [alert(message)][1] expects message to be a string or an object it can ...
user avatar
  • 1,749
6 votes
Accepted

Return JSON using the Joomla Framework

I finally found what seems to be the "correct" way to do this. Even if I used sendHeaders, the additional Content-Type was being added and that got returned as it was added later. I followed through ...
user avatar
  • 541
6 votes

Making an ajax-based template?

My advice to you - avoid this. It's a recipe for many problems. A website owner who wanted this ended up paying us a lot of money just to fix the problems that arose from using this strategy (there ...
user avatar
  • 3,176
6 votes
Accepted

How to get Ajax response within a Module?

For the ajax request to map to your module's helper the class must be named "modFilefinderHelper" From the documentation: Module requests must include the module variable in the URL, paired with ...
user avatar
  • 3,134
5 votes

How can I use com_ajax to load and unload another module (for Adaptive Design)

com_ajax is only really used if the data for the module is supported (JSON based), although it has other features. In some cased the easiest way to "just" load a module, is to create a new template ...
user avatar
5 votes
Accepted

Ajax call to component from menu item

I'm assuming your using JQuery. If your using Mootools let me know, and I'll update this. Your AJAX call can look something like this: $.ajax({ url : urlToSend, ...
user avatar
  • 226
5 votes
Accepted

Submitting a Form with file inputs via AJAX

I managed to make it work. Sharing the same which can help others. No change on the form and controller. Slight changes on the model and ajax model public function uploadPicture() { $input = ...
user avatar
  • 2,651
5 votes
Accepted

How to execute an ajax script to update form fields in an .xml file rendered by Akeeba FOF?

You can use JSON format in the controller directly by adding .json suffix and changing format in your URL to json. In this case the controller would be placed in /administrator/components/com_example/...
user avatar
  • 8,177
4 votes

What is the proper way to make an AJAX call in component?

If you are 100% sure there's no thrid-party plugin adding any Javascript output, a pure json_encode works Ok. But ... for example JomSocial adds "" to the whole site. So... a handy trick, wrap ...
user avatar
  • 7,415
4 votes

Override default php session

Edit: It seams that the answer is not correct. The default Joomla Session Handler (Database) does not lock the session while processing. So you don't have to worry about locking. Anyway its possible ...
user avatar
4 votes

Return JSON using the Joomla Framework

Took a little digging but I see the issue https://github.com/joomla-framework/application/blob/master/src/AbstractWebApplication.php If you look at the setHeader function it does not actually set ...
user avatar
4 votes
Accepted

Writing custom method to save form data

Initially I figured the best would be to use the controller method save(), which I finally got working like this: $path = JPATH_ADMINISTRATOR . '/components/com_anycomponent; JLoader::register('...
user avatar
  • 738
4 votes
Accepted

Adding ajax in Joomla Custom Module

Well in case you don't want to use Joomla Ajax Interface, you could also do it like this: You have a module and you have your component. The script code goes into a javascript file or the view of the ...
user avatar
  • 346
4 votes

Ajax error when attempting component updates

I recently encountered this XMLHttpRequest error myself. The root of the problem caused 3 different issues. SOLUTION: In my case, the problem was caused by an incorrect setting for the public $...
user avatar
  • 2,330
4 votes
Accepted

how to refresh Joomla token in form by AJAX

I wanted to answer your earlier question about this yesterday, but someone was already answered this partially for you. So according to me your original Login Form token field should be a bit changed ...
user avatar
  • 2,436
4 votes

how to refresh Joomla token in form by AJAX

Playing with the sessions is usually not a very safe thing to do - you could create more problems by trying to find a solution. You can do one (or both) of the following: Increase the Session ...
user avatar
  • 3,176
4 votes
Accepted

How to get user object in Ajax call

When importing classes using use statement, it has to be outside of your class. When put inside a class, it's interpreted as a use of trait. And when used inside a method it will cause a syntax error. ...
user avatar
  • 8,177
3 votes

How to load Joomla session from external AJAX call

To load the session you need to get it from JFactory. $session = JFactory::getSession(); Read more on How to access session variables set by an external script.
user avatar
3 votes
Accepted

Stop robots from getting site/article content

There is no easy solution, because bots have different behaviour. I would split them into 4 categories and solution for each: Legitimate crawlers (i.e. Google) - these usually respect robots.txt and ...
user avatar
  • 156
3 votes

Stop robots from getting site/article content

If you don't want content to be publicly accessible then use Joomla's ACL to restrict access, removing access for the default (public) usergroup. If you don't do that, or something similar, then your ...
user avatar
3 votes

Stop robots from getting site/article content

One method would be to block accesses from crawlers, though this depends on being able to identify them. The following article has some good examples of how to enhance the Joomla security. http://...
user avatar
3 votes

Override default php session

Welcome to the world of asynchronous calls. My advice is don't use sessions for the AJAX/RESTful calls at all. The most I would do is have some sort of authentication token so you know who is making ...
user avatar
3 votes
Accepted

Override default php session

You don't have to write your own JSession class, but you'll need to write a class extending JSessionStorage to integrate with Joomla's session handling. Most likely you'll run into trouble when ...
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible