Skip to content

Commit ee7fc71

Browse files
committed
Add partial ajax rendering
1 parent 90de72d commit ee7fc71

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Ajax/common/traits/JsUtilsAjaxTrait.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,14 @@ protected function _ajax($method, $url, $responseElement = "", $parameters = [])
5454
if (isset($headers)) {
5555
$ajaxParameters["headers"] = $headers;
5656
}
57+
if (isset($partial)) {
58+
$ajaxParameters["xhr"] = "xhrProvider";
59+
$retour .= "var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;" . $partial . ";}; };";
60+
}
5761
$this->createAjaxParameters($ajaxParameters, $parameters);
5862
$retour .= "$.ajax({" . $this->implodeAjaxParameters($ajaxParameters) . "}).done(function( data, textStatus, jqXHR ) {\n";
5963
$retour .= $this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader, ($historize ? $originalSelector : null)) . "});\n";
64+
6065
$retour = $this->_addJsCondition($jsCondition, $retour);
6166
if ($immediatly)
6267
$this->jquery_code_for_compile[] = $retour;
@@ -735,6 +740,10 @@ private function _postForm($url, $form, $responseElement, $parameters = []) {
735740
if (isset($headers)) {
736741
$ajaxParameters["headers"] = $headers;
737742
}
743+
if (isset($partial)) {
744+
$ajaxParameters["xhr"] = "xhrProvider";
745+
$retour .= "var xhr = $.ajaxSettings.xhr();function xhrProvider() {return xhr;};xhr.onreadystatechange = function (e) { if (3==e.target.readyState){let response=e.target.responseText;" . $partial . ";}; };";
746+
}
738747
$this->createAjaxParameters($ajaxParameters, $parameters);
739748
$retour .= "$.ajax({" . $this->implodeAjaxParameters($ajaxParameters) . "}).done(function( data ) {\n";
740749
$retour .= $this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback, $hasLoader) . "});\n";

0 commit comments

Comments
 (0)