1

こんにちは、ここに私のコードを以下に示します。

index.phtml コード

<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

info.phtml を次のように仮定します。

コントローラーに何を書き込めばいいのかわからない...たくさんのチュートリアルをチェックしましたが、ZF2のようなものでは機能しません

public function init()
{
    $ajaxContent=$this->_helper->helper();
    $ajaxContent->addActionContext('info','html');
    $ajaxContent->initContext();

}

この問題を解決する他の方法はありますか?

4

2 に答える 2

0

コントローラーで次のようなものを使用できます。

     public function addressdeleteAction()
{
    $response = $this->getResponse();    
    $post_data = $request->getPost();    

    $response->setContent(\Zend\Json\Json::encode(array('id' => 100))); 

    return $response;

}
于 2013-07-18T13:35:46.373 に答える