I'm developing a web application, where I use jQuery to make Ajax calls to the server.
I'm using the url view helper to insert the URL to be called. The code inside my view scripts looks like the following:
$.ajax({
type: "POST",
url: "<?php echo $this->url(array('action' => 'myaction', 'controller' => 'mycontroller'), null, true); ?>",
dataType: "html",
data: { id: myId, format: 'xml' },
beforeSend: function() {
// Show pseudoprogress
},
success: function(html) {
// Process response
},
error: function() {
// Show an error message
}
});
The system is working fine, but because of this approach I can't extract the Javascript code to separate files, because I always need to run it through the PHP interpreter first.
I wonder if there is a better way to do it, so that I can keep the Javascript code as "PHP-clean" as possible (and eventually, in separate files).
Thanks in advance.