ajax.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaCoreSamples Samples
  7. * @{
  8. */
  9. /**
  10. * @page samples
  11. * @section ajax AJAX loader
  12. */
  13. $aPathInfo = pathinfo(__FILE__);
  14. require_once ($aPathInfo['dirname'] . '/../inc/header.inc.php');
  15. require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
  16. if (bx_get('ajax') || (isset( $_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')) {
  17. sleep(3);
  18. echo '<div class="bx-def-padding bx-def-color-bg-block">AJAX content here: ' . bx_time_js(time(), BX_FORMAT_DATE_TIME, rand(0, 1)) . '</div>';
  19. exit;
  20. }
  21. $oTemplate = BxDolTemplate::getInstance();
  22. $oTemplate->addJs('jquery.webForms.js');
  23. $oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
  24. $oTemplate->setPageHeader ("AJAX");
  25. $oTemplate->setPageContent ('page_main_code', PageCompMainCode());
  26. $oTemplate->getPageCode();
  27. /**
  28. * page code function
  29. */
  30. function PageCompMainCode()
  31. {
  32. ob_start();
  33. ?>
  34. <script>
  35. function ajaxTest(e)
  36. {
  37. bx_loading_btn(e, 1);
  38. getHtmlData('bx-result', 'samples/ajax.php?ajax=1', function () {
  39. bx_loading_btn(e, 0);
  40. });
  41. }
  42. </script>
  43. <button class="bx-btn" onclick="getHtmlData('bx-result', 'samples/ajax.php?ajax=1')">Нажми Меня</button>
  44. <button class="bx-btn bx-def-margin-left" onclick="ajaxTest(this)">И Меня!</button>
  45. <div class="bx-clear"></div>
  46. <div id="bx-result" style="width:500px; height:200px;" class="bx-def-border bx-def-round-corners bx-def-margin-top"></div>
  47. <?php
  48. return DesignBoxContent("AJAX", ob_get_clean(), BX_DB_PADDING_DEF);
  49. }
  50. /** @} */