Zend Framwork 2.
, Skareton Wasabilib https://github.com/WasabiLib/wasabilib_zf2_skeleton_application. .
, .
: jQuery, ZF2
- application.config.php.
- wasabilib.min.js jquery layout.phtml
.phtml :
<form id="simpleForm" class="ajax_element" action="simpleFormExample" method="POST">
<input type="text" name="written_text">
<input type="submit" value="try it">
</form>
phtml , .
:
public function simpleFormExampleAction(){
$postArray = $this->getRequest()->getPost();
$input = $postArray['written_text'];
$response = new Response(new InnerHtml("#element_simple_form","Server Response: ".$input));
return $this->getResponse()->setContent($response);
}
"ajax_element", , xmlhttp-. , . , "simpleForm". - "//", .
WasabiLib\Ajax\Response.
InnerHtml , html .
"element_simple_form". InnerHtml . , #yourElementId .yourClassSelector. "#" ".
The second parameter is the text that you want to fill with this element.
The response object can handle many more answers that you can add with
$response->add($anotherResponseType);
A list of possible response types is on the wasabilib.org home page.
The module is built to handle ajax response requests in a very simple way. Once you understand the behavior, you can handle almost all of the practical needs of ajax.
source
share