AlanMar

e107

May 5th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.25 KB | None | 0 0
  1. <?php
  2.  
  3.   if ($_GET)
  4.     error_log('GET PARAMETERS BEFORE CLASS2: ' . print_r($_GET, true));
  5.  
  6.   require_once("class2.php");
  7.  
  8.   if ($_GET)
  9.     error_log('GET PARAMETERS AFTER CLASS2: ' . print_r($_GET, true));
  10.  
  11.   require_once(HEADERF);
  12.  
  13. //-----------------------------------------------------------------------------  
  14. if ($_GET)
  15. {
  16.   if (e_AJAX_REQUEST)
  17.   {
  18.     $dataOut   = '';
  19.     $processed = false;
  20.  
  21.     if ($_GET['test_value'])
  22.     {
  23.       $processed    = true;
  24.       $data         = $_GET['test_value'];
  25.       $val1         = $data['val1'];
  26.       $val2         = $data['val2'];
  27.       $val3         = $data['val3'];
  28.       // Do something with the values..., then return
  29.       $dataOut      = 'Some result data';
  30.     }
  31.  
  32.     if ($processed)
  33.     {
  34.       $dataOut = json_encode($dataOut);
  35.       header('Content-Type: application/json; charset=UTF-8');
  36.       header('Content-Length: ' . strlen($response));
  37.       echo $response;
  38.       die();
  39.     }
  40.   }
  41. }
  42.  
  43. //-----------------------------------------------------------------------------
  44. $text = "
  45.  <script>
  46.    function sendSomeData()
  47.    {
  48.      var groupArray = {};
  49.      groupArray['val1'] = 'abc';
  50.      groupArray['val2'] = 'def';
  51.      groupArray['val3'] = 'ghi';
  52.  
  53.      var params =
  54.      {
  55.        'test_value': groupArray,
  56.        'ajax_used': '1'
  57.      };
  58.  
  59.      $.ajax(
  60.      {
  61.        url        : '" . e_SELF . "',
  62.        type       : 'GET',
  63.        data       : params,
  64.        async      : true,
  65.        cache      : false,
  66.        contentType: 'text/json; charset=utf-8',
  67.        dataType   : 'json',
  68.      
  69.        success: function(data, status)
  70.        {
  71.          alert('success');
  72.        },
  73.  
  74.        error: function(xhr, status, error)
  75.        {
  76.          alert('fail');
  77.        }
  78.      });
  79.    }
  80.    
  81.    $(document).ready(function()
  82.    {
  83.      $('#mybutton').click(function(e)
  84.      {
  85.        sendSomeData();
  86.      });
  87.    });
  88.  </script>
  89.  
  90.  <input id='mybutton' type='button' value='Press'></input>
  91. ";
  92.  
  93. //-----------------------------------------------------------------------------
  94. $caption = $tp->toHtml($caption);
  95. $text = $tp->toHtml($text, false, "retain_nl");
  96. $ns->tablerender($caption, $text);
  97. require_once(FOOTERF);
  98. ?>
Advertisement
Add Comment
Please, Sign In to add comment