Guest User

Untitled

a guest
Mar 21st, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. jQuery(document).ready(function(){
  2. jQuery('.cl_link_buttons').val('id').click(function() {
  3.  
  4. var currentid = jQuery(this).attr('id');
  5.  
  6. //alert(currentid);
  7. console.log(currentid);
  8.  
  9. jQuery.ajax ( data = {
  10. action: 'cleanlinks_ajax_get_post_data',
  11. url: ajaxurl,
  12. type: 'POST',
  13. dataType: 'text',
  14. "currentid" : currentid
  15.  
  16. });
  17.  
  18. jQuery.post(ajaxurl, data, function(response) {
  19.  
  20. var dataz = response;
  21. alert( dataz );
  22. console.log (dataz); //show json in console
  23.  
  24.  
  25. });
  26.  
  27. return false;
  28.  
  29. }); //end click event
  30. }); //end doc ready
  31.  
  32. add_action("wp_ajax_cleanlinks_ajax_get_post_data", "cleanlinks_ajax_get_post_data");
  33. add_action("wp_ajax_nopriv_cleanlinks_ajax_get_post_data", "cleanlinks_ajax_get_post_data");
  34.  
  35. function cleanlinks_ajax_get_post_data() {
  36.  
  37. $from_ajax = $_POST['currentid'];
  38.  
  39. echo "do" . $from_ajax . "something";
  40.  
  41. die();
  42.  
  43.  
  44. }
  45.  
  46. var dataString = {lat: '55.56', lng: '25.35', action:'report_callback'};
  47. $.ajax({
  48. url: "http://domain.net/wp-admin/admin-ajax.php",
  49. type: "POST",
  50. //some times you cant try this method for sending action variable
  51. //action : 'report_callback',
  52. data:dataString,
  53. success: function(data){
  54. console.log(data);
  55.  
  56. },
  57. error: function() {
  58. console.log("Error");
  59. }
  60. });
  61.  
  62. if ( empty( $_REQUEST['action'] ) ) {...}
  63. Line 26
  64.  
  65. jQuery.post(ajaxurl, {action:'cleanlinks_ajax_get_post_data'}, function(response) {
  66. console.log (response);
  67. });
  68.  
  69. function doAjax() {
  70. $result = getPosts();
  71. echo json_encode($result, true);
  72. die();
  73. }
  74.  
  75. add_action( 'wp_ajax_my_action', [$object, 'my_method']);
  76.  
  77. wp_enqueue_script( 'search_js', get_template_directory_uri() . '/js/search.js', array( 'jquery' ), null, true );
  78. wp_localize_script( 'search_js', 'ajaxurl', admin_url( 'admin-ajax.php' ) );
  79.  
  80. $('#search_input').autocomplete({
  81. source: function(request, response) {
  82.  
  83. $.ajax({
  84. type: 'POST',
  85. dataType: 'json',
  86. url: ajaxurl,
  87. data: 'action=my_custom_action_search&search_criteria=' + request.term,
  88. success: function(data) {
  89. response(data);
  90. },
  91. error: function(errorThrown){
  92. console.log(errorThrown);
  93. }
  94. });
  95. },
  96. minLength: 3
  97. });
  98.  
  99. },
  100. error: function (xhr, status) {
  101. alert("Sorry, there was a problem!");
  102. },
  103. complete: function (xhr, status) {
  104. $('#showresults').slideDown('slow')
  105. }
  106. });
  107. });
  108.  
  109. if
  110.  
  111. function my_function(){
  112. $id = $_POST['variation_id'];
  113.  
  114. if(isset($_POST['variation_id'])) {
  115.  
  116.  
  117. //your coded function
  118.  
  119.  
  120. die();
  121. }
  122.  
  123.  
  124.  
  125. }// end function
Add Comment
Please, Sign In to add comment