Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 20th, 2012  |  syntax: None  |  size: 0.47 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to send an empty array from JS to PHP using JSON?
  2. <?
  3. if ($_GET['test']) {
  4.     $data = $_GET['data'];
  5.     print_r($data);
  6.     exit;
  7. }
  8. ?>
  9. <head>
  10.     <script type="text/javascript" src="jquery-1.6.4.min.js"></script>
  11. </head>
  12. <script type="text/javascript">
  13.     $.getJSON('temp.php', {
  14.         "test": 1,
  15.         "data": []
  16.     })
  17. </script>
  18.        
  19. if (! isset($data = $_GET['data']))
  20.     $data = array();
  21.        
  22. $.getJSON('temp.php', {
  23.     "test": 1,
  24.     "data": JSON.stringify([])
  25. })