您好这里的人是我下面的code,
Hello People here is my code below,
index.phtml code
index.phtml code
<div class="view clearfix" onClick="ajaxinfo()">Info</a></div>
<script>
function ajaxinfo(){
var id = 100;
$.ajax({
type: "POST",
url:"http://localhost/zf2/info/format/html",
data:id,
success:function(data){alert('ajax data success');},
error:function(){alert('ajax data failed to fetch');}
});
return false;
}
</script>
你可以看到IAM试图通过ID = 100〜 info.phtml
页,并试图让HTML数据传回从 info.phtml
as you can see iam trying to pass id=100 to info.phtml
page and try to get html data back from info.phtml
让我们假设info.phtml为
lets assume info.phtml as
荫不知道要写什么在控制...我检查洙很多教程,但是对于ZF2像
Iam not sure what to write in in controller ... i checked soo many tutorial , but it does not work for ZF2 like
public function init()
{
$ajaxContent=$this->_helper->helper();
$ajaxContent->addActionContext('info','html');
$ajaxContent->initContext();
}
有没有解决这个问题的任何其他方式?
is there any other way to resolve this problem.?
您可以使用像这样的控制器:
you can use something like this in the controller:
public function addressdeleteAction()
{
$response = $this->getResponse();
$post_data = $request->getPost();
$response->setContent(\Zend\Json\Json::encode(array('id' => 100)));
return $response;
}