Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- jQuery(document).ready(function(){
- jQuery('.cl_link_buttons').val('id').click(function() {
- var currentid = jQuery(this).attr('id');
- //alert(currentid);
- console.log(currentid);
- jQuery.ajax ( data = {
- action: 'cleanlinks_ajax_get_post_data',
- url: ajaxurl,
- type: 'POST',
- dataType: 'text',
- "currentid" : currentid
- });
- jQuery.post(ajaxurl, data, function(response) {
- var dataz = response;
- alert( dataz );
- console.log (dataz); //show json in console
- });
- return false;
- }); //end click event
- }); //end doc ready
- add_action("wp_ajax_cleanlinks_ajax_get_post_data", "cleanlinks_ajax_get_post_data");
- add_action("wp_ajax_nopriv_cleanlinks_ajax_get_post_data", "cleanlinks_ajax_get_post_data");
- function cleanlinks_ajax_get_post_data() {
- $from_ajax = $_POST['currentid'];
- echo "do" . $from_ajax . "something";
- die();
- }
- var dataString = {lat: '55.56', lng: '25.35', action:'report_callback'};
- $.ajax({
- url: "http://domain.net/wp-admin/admin-ajax.php",
- type: "POST",
- //some times you cant try this method for sending action variable
- //action : 'report_callback',
- data:dataString,
- success: function(data){
- console.log(data);
- },
- error: function() {
- console.log("Error");
- }
- });
- if ( empty( $_REQUEST['action'] ) ) {...}
- Line 26
- jQuery.post(ajaxurl, {action:'cleanlinks_ajax_get_post_data'}, function(response) {
- console.log (response);
- });
- function doAjax() {
- $result = getPosts();
- echo json_encode($result, true);
- die();
- }
- add_action( 'wp_ajax_my_action', [$object, 'my_method']);
- wp_enqueue_script( 'search_js', get_template_directory_uri() . '/js/search.js', array( 'jquery' ), null, true );
- wp_localize_script( 'search_js', 'ajaxurl', admin_url( 'admin-ajax.php' ) );
- $('#search_input').autocomplete({
- source: function(request, response) {
- $.ajax({
- type: 'POST',
- dataType: 'json',
- url: ajaxurl,
- data: 'action=my_custom_action_search&search_criteria=' + request.term,
- success: function(data) {
- response(data);
- },
- error: function(errorThrown){
- console.log(errorThrown);
- }
- });
- },
- minLength: 3
- });
- },
- error: function (xhr, status) {
- alert("Sorry, there was a problem!");
- },
- complete: function (xhr, status) {
- $('#showresults').slideDown('slow')
- }
- });
- });
- if
- function my_function(){
- $id = $_POST['variation_id'];
- if(isset($_POST['variation_id'])) {
- //your coded function
- die();
- }
- }// end function
Add Comment
Please, Sign In to add comment