Problem with using Jquery.ajax over .load on Zend
- by Matthew
Right now, what i'm trying to do is to replace a label on the front page with a block of html. Right now, the page basically has:
<label id="replace"></label>
the js currently has:
$(document).ready(function(){
$("#replace").load('/test');
});
the Zend class function has:
public function indexAction(){
$this->_helper->layout()->disableLayout();
$this->_view->message = "This is from TestController index";
}
and finally the index.phtml template simply has:
<?php echo $this->message;?>
Right now, I want to change the code around so that instead of just replacing that label with the same message, it would do a POST where the function will pull out a parameter, do something (like for instance, go to the database and pull something out with the POST parameter) and then return the message.
I've tried editing the js so that it would look like:
$.post('/test', {param : "test_param"},
function(data) {$("#replace").html(data);});
or
$.ajax({
type: 'POST',
url: '/test',
data: "{param:test_param}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {$("#replace").html(data);}
});
and neither worked. I took a step back and tried to replicate the .load functionality and do:
$.ajax({
url: '/test',
success: function(data) {
$('#replace').html(data);
alert('Load was performed.');
}
});
and it doesn't work either.
Anyone have any tips on how to go about doing this?