Home » Magento10 March 2016

Magento: Using AJAX with Prototype JS

This article shows how to use AJAX on Magento with Prototype Javascript Library.

Scenario

I had one scenario where I had to check whether a customer is already registered or not via AJAX.

– User will enter his/her email address in a text box and press the ‘Continue’ button.
– After that, I need to check if that email is already registered or not.
– If the email is already registered, then I have to show an alert with some message in it.
– If the email is not registered, then I need to proceed to next Javascript function.

Solution

Below is the text fieldcode where user have to type his/her email address. Also, there is a ‘Continue’ button code. When the ‘Continue’ button is clicked, then isRegisteredEmail() Javascript function is called.

Below is the isRegisteredEmail() Javascript function. This function calls your module’s controller’s “checkEmailAction()” function via AJAX ‘get’ method. It passes user’s email as parameter. Based on the response value, it will alert the user or proceed to nextStep function. Here, I have assumed that your module’s name is “YourModule” and your controller name is “Xyz“.

Here is the function to check registered email which is to be written in your controller’s class (app/code/community/YourNamespace/YourModule/controllers/XyzController.php).

Hope this helps. Thanks.

Magento

Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed

Comments are closed.