本文介绍了阿贾克斯的Zend Framework2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好这里的人是我下面的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;
}
这篇关于阿贾克斯的Zend Framework2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!