Magento 1.x – How to make an ajax call in a backend fieldset field


If you are making a backend admin form, and you need to make an ajax call to retrieve some information, the following tutorial will help you:

In this particular case, we are going to find an sku thumbnail and show it up next to a search button.

1- Add an input where we are going to find the sku on our admin form:

2- Add the after html behaviour to our fieldset, here we are going to add:

  • A button to call our ajax function.
  • An spam where we are going to put the results.
  • The javascript function itself with the Ajax request.

3- Create a new action called loadcategoryproductthumbnail under controllers/Adminhtml/MyModuleController with the logic we need, in this case:

  • Get a product from an sku that came from the call request.
  • Get the product thumbnail.
  • Report an error via json in case the product do no exists.
  • Return the full product image tag in case that it exists.

And that’s it, don’t forget to clean cache, and you will see something like that: