I’d like to use pure Javascript httprequest to post a message to a controller/action in Zend and get back a response that I can process back in the page with a callback function, classically.
Two questions:
- how can I format the POST string taking into account the baseurl imposed by Zend (in the classical case I point to a php file).
- what should I do – the simplest possible (I understand there are several possible implementations) – in the action method so that to return a response.
Again, no jQuery, JSON, prototype or other library.
The use case is the following: I have a view with a form section. One of the inputs is a select drop down list, I click on an item of that list, I trigger an Ajax request to controller/action and get back instantly from the server a value that I update a text area with.
The url you post to is all dependent on your controllers and modules structure, so that makes it hard for us to give you a detailed answer. But for a simple example, try this out.
form post to http://domain.com/index/textarea
the controller: IndexController.php
the view: textarea.phtml
What ever is in your view, will then be returned to your JavaScript.
For a better implementation read up on AjaxContext switching, which will allow you to use JSON, which means you can drop the view file, and ZF will simply return a JSON encoded string for you.