Advertisement
obernardovieira

Get array from PHP using $.post Jquery

Jan 25th, 2014
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2. <head>
  3. <script>
  4. function getphp(hora) {
  5.     $.post("page.php",
  6.     {'value': 2, 'plus': 4},
  7.     function(data,status){
  8.         alert("value = "+data[0]+"+4="+data[1]+" - "+status);//data.length
  9.     }, "json");
  10. }
  11. </script>
  12. </head>
  13. </html>
  14.  
  15. //page.php
  16.  
  17. <?php
  18. $val1= $_POST['value'];
  19. $val2 = $_POST['plus'];
  20. $re = array();
  21. $re[0] = $val1;
  22. $re[1] = $val1+$val2;
  23. echo json_encode($re);
  24. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement