AJAX extension
Method | Description | Available form version |
---|---|---|
BX.ajax | Low-level function to send Ajax requests. | |
BX.ajax.Setup | Specifies the by-default values for parameters of [link=653461]ajax requests[/link]. | |
BX.ajax.get | Simple GET query sending and passing the result to a handler. | |
BX.ajax.post | Simple POST query sending and passing of the result to a handler. | |
BX.ajax.insertToNode | Request data by the specified address and inserts reply into a specified container. | |
BX.ajax.load | Loads the resource query abd calls a handler. | |
BX.ajax.loadJSON | Loads a JSON-object from the specified URL and passes it to a handler. | |
BX.ajax.loadScriptAjax | Loads and executes a script or series of scripts. |
Example
<? require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php"); $APPLICATION->SetTitle("AJAX"); CJSCore::Init(array('ajax')); $sidAjax = 'testAjax'; if(isset($_REQUEST['ajax_form']) && $_REQUEST['ajax_form'] == $sidAjax){ $GLOBALS['APPLICATION']->RestartBuffer(); echo CUtil::PhpToJSObject(array( 'RESULT' => 'HELLO', 'ERROR' => '' )); die(); } ?> <div class="group"> <div id="block"></div > <div id="process">wait ... </div > </div> <script> window.BXDEBUG = true; function DEMOLoad(){ BX.hide(BX("block")); BX.show(BX("process")); BX.ajax.loadJSON( '<?=$APPLICATION->GetCurPage()?>?ajax_form=<?=$sidAjax?>', DEMOResponse ); } function DEMOResponse (data){ BX.debug('AJAX-DEMOResponse ', data); BX("block").innerHTML = data.RESULT; BX.show(BX("block")); BX.hide(BX("process")); BX.onCustomEvent( BX(BX("block")), 'DEMOUpdate' ); } BX.ready(function(){ /* BX.addCustomEvent(BX("block"), 'DEMOUpdate', function(){ window.location.href = window.location.href; }); */ BX.hide(BX("block")); BX.hide(BX("process")); BX.bindDelegate( document.body, 'click', {className: 'css_ajax' }, function(e){ if(!e) e = window.event; DEMOLoad(); return BX.PreventDefault(e); } ); }); </script> <div class="css_ajax">click Me</div> <?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/footer.php");?>
© «Bitrix24», 2001-2024