Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. /*
  2. PHP
  3. */
  4. add_action( 'wp_ajax_bookmark', 'handle_bookmark' );
  5. add_action( 'wp_ajax_nopriv_bookmark', 'handle_bookmark');
  6.  
  7. function handle_bookmark() {
  8. $user = $_REQUEST["user"];
  9. $postID = $_REQUEST["postID"];
  10.  
  11. $res = update_field($selector, $value, $post_id);
  12. if($res):
  13. echo json_encode(array(
  14. "success" => true,
  15. "message" => "message message message"
  16. ));
  17. else:
  18. echo json_encode(array(
  19. "success" => false,
  20. "message" => "message message message"
  21. ));
  22. endif;
  23.  
  24. exit();
  25. }
  26.  
  27. /*
  28. jQuery
  29. */
  30.  
  31. $.ajax({
  32. method: "POST",
  33. url: "url de ajax de wordpress",
  34. data: { userID: "John", postID: "Boston" }
  35. })
  36. .done(function( msg ) {
  37. console.log( "Data Saved: " + msg );
  38. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement