1

I am quite new to magento. Can you suggest a tutorial for using ajax in magento? I checked this but couldn't find a step by step tutorial for newbies like me. My requirement is, I need to check availability of the username when user enters a "username", without refreshing the page. I want to sent the entered username to a controller and check if it's already used, and sent back a message to the user reg its availability. Pls help me in achieving this using ajax.

Gerard de Visser
  • 7,590
  • 9
  • 50
  • 58
user2268578
  • 11
  • 1
  • 4

1 Answers1

2

You could try creating a small Module that handles the AJAX requests and returns true/false if the username is already in use.

I would suggest reading an article in setting up a module. Google "Magento Controller Dispatch and Hello World", first link is a good article.

When you've set up a basic Module, I'd recommend making an action echo "Testing" for use later with the AJAX-request.

Back to the form and the input-field. I'd try adding an event listener to the input-field, so that when it changes (i.e. when the user types something into the field), a function is triggered. (Google "onchange input text prototype", second link.)

In that function you can use AJAX to POST a request to your Module's action and use the result of that action to display a message if the username is available or not.(http://www.magentogarden.com/blog/working-with-ajax-and-json-in-magento.html)

If you got the AJAX request to return "Testing" from the action you wrote earlier, you can change the echo of the action to true/false depending on the request you make to the database.

(Here's an article which uses the database to fetch a list of users for some more guidance: http://mysillypointofview.richardferaro.com/2010/09/07/how-to-pull-the-list-of-customers-from-magento-to-an-external-site/ )

EricPolman
  • 48
  • 5