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.
-
Hope this help: http://www.excellencemagentoblog.com/magento-blogs/ajax-magento-blogs/ http://www.atwix.com/magento/ajax-requests-in-magento/ – Pankaj Pareek Jun 24 '13 at 14:04
-
Hi , Thanks for the suggestion. I went through these links. But not very helpful for a beginner. – user2268578 Jun 24 '13 at 14:06
-
maybe that answer can help you: http://stackoverflow.com/a/19397595/219986 – OSdave Sep 17 '14 at 11:13
1 Answers
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/ )

- 48
- 5