Example of a JSON encoded repsonse


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. $answer = $_POST['answer'];
  4.  
  5. if($answer == '8'){
  6.  
  7. 'success' => 1,
  8. 'message' => 'Correct! 3 + 5 = 8'
  9. )
  10. );
  11.  
  12. exit();
  13.  
  14. }else{
  15.  
  16. 'success' => 0,
  17. 'message' => 'Sorry, that is the wrong answer.'
  18. )
  19. );
  20.  
  21. exit();
  22.  
  23. }
  24.  
  25.  
  26. // just to have an extra failsafe!
  27. 'message' => 'You must choose a valid response.'
  28. )
  29. );

URL: http://www.dropthenerd.com/ajax-a-simple-approach-that-you-will-use-and-reuse/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.