Title: colome's Replies | WordPress.org

---

# colome

  [  ](https://wordpress.org/support/users/colome/)

 *   [Profile](https://wordpress.org/support/users/colome/)
 *   [Topics Started](https://wordpress.org/support/users/colome/topics/)
 *   [Replies Created](https://wordpress.org/support/users/colome/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/colome/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/colome/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/colome/engagements/)
 *   [Favorites](https://wordpress.org/support/users/colome/favorites/)

 Search replies:

## Forum Replies Created

Viewing 6 replies - 1 through 6 (of 6 total)

 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [How to make an ajax call with parameters into WordPress site](https://wordpress.org/support/topic/how-to-make-an-ajax-call-with-parameters-into-wordpress-site/)
 *  Thread Starter [colome](https://wordpress.org/support/users/colome/)
 * (@colome)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/how-to-make-an-ajax-call-with-parameters-into-wordpress-site/#post-8284541)
 * Thanks catacausic!
 * I answer myself:
    Then upload the js (ping.js) inside my theme js folder in my
   case: public_html/wp-content/themes/metone_wp/js:
 *     ```
       function PING(){
           $imatge=document.getElementById('image');
           $imatge.show();
           $ip=document.getElementById('ip');
           $val=ip.value;
           $params={action:'ping_php',ip: $val}
   
           jQuery.ajax({
              type: "POST",
              url: ajax_object.ajaxurl,
              cache: false,
              //contentType: "application/json; charset=utf-8",
              //dataType: "json",
              data: $params, 
              success: onSuccesPing,
              error: onErrorPing
              //error: onErrorPing,
              //crossDomain:true
            });
          //another way to make the same
          // jQuery.post(ajax_object.ajaxurl, $params,function (response){
          //   document.getElementById("notification").innerHTML=response;
          //   document.getElementById("image").style.display = "none";
          //  });
       }
       function onSuccesPing(data,status)
       {
          jQuery("#notification").fadeIn(0); 
          document.getElementById("notification").innerHTML=data;
          document.getElementById("image").style.display = "none";
          jQuery("#notification").delay(5200).fadeOut(300);
   
       }
       function onErrorPing(data,status)
       {
          jQuery("#notification").fadeIn(0);  
          document.getElementById("notification").innerHTML=data.responseText;
          document.getElementById("image").style.display = "none";
          jQuery("#notification").delay(5200).fadeOut(300);
       }
       ```
   
 * The trick to pass paramters to the ajax call is the line:
 * `$params={action:'ping_php',ip: $val}`
 * **$params **is an array of parameters, is necesary to have a mandatory parameter**“
   action”** that refers the php function defined below normaly at the functions.
   php of wordpress theme.
 * The parameters can be accessed at the php function as $_POST variables in my 
   case **$_POST[‘ip’]**.
 * to define the functions in wordpress I was used the theme functions.php, and 
   and this piece of code:
 *     ```
       //----------------------------- test utils ini-----------------------------------------
       function ping_php ()
       {
            $ip=$_POST['ip'];
           exec("ping -c 3 ".$ip." 2>&1", $output, $status);
           foreach ($output as $key => $value) {
               echo ($value.'<br>');
           }
          die();
       }
       add_action( 'wp_ajax_ping_php', 'ping_php' );
       add_action( 'wp_ajax_nopriv_ping_php', 'ping_php' );
       function enqueue_scripts() {
               wp_register_script('ajax-script',  get_template_directory_uri() .'/js/ping.js', array('jquery'), 1.0 ); 
               wp_localize_script( 'ajax-script', 'ajax_object', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); // setting ajaxurl
           wp_enqueue_script( 'ajax-script'); // jQuery will be included automatically
       }
       add_action('wp_enqueue_scripts', 'enqueue_scripts');
       //---------------------------test utils end ----------------------------------------------
       ```
   
 * is important to folow the correct order to enqueue the script
 * First the **wp_register_script**: include the directory of the js file and jquery
   enabled
    then **wp_localize_script**: usefull to pass variables from wordpress
   to my script in my case the url of ajax processing: ajaxurl finally **wp_enqueue_script**
 * It is also importate add **wp_die()** or **die()** at the end of the php function,
   if not the function returns **“0”**
 * It is also very inportant that the function names match exactly:
 * add_action( ‘wp_ajax_**ping_php**‘, ‘ping_php’ );
    add_action( ‘wp_ajax_nopriv_**
   ping_php’**, ‘ping_php’ );
 * with the parameter “action” of the ajax call
    -  This reply was modified 9 years, 10 months ago by [colome](https://wordpress.org/support/users/colome/).
    -  This reply was modified 9 years, 10 months ago by [colome](https://wordpress.org/support/users/colome/).
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[TicketPress] close ticket](https://wordpress.org/support/topic/close-ticket-1/)
 *  Thread Starter [colome](https://wordpress.org/support/users/colome/)
 * (@colome)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/close-ticket-1/#post-6886871)
 * ok Sorry I don’t see the field….tanks
 * Could it be possible that the administrator be notified by email if you have 
   a new ticket ?
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [Text widgets showing up on the wrong pages since WordPress 4.4 update](https://wordpress.org/support/topic/text-widgets-showing-up-on-the-wrong-pages-since-wordpress-44-update/)
 *  [colome](https://wordpress.org/support/users/colome/)
 * (@colome)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/text-widgets-showing-up-on-the-wrong-pages-since-wordpress-44-update/#post-6850873)
 * I was the same issue The widgets I’ve created doesn’t appear. Instead, a random
   one from somewhere else on the site does ……
 * I was about to go crazy!!!!
 * until I found this solution, thanks a lot!!
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Slide Puzzle] more than one puzzle](https://wordpress.org/support/topic/more-than-one-puzzle/)
 *  Plugin Author [colome](https://wordpress.org/support/users/colome/)
 * (@colome)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/more-than-one-puzzle/#post-4830840)
 * Sorry daniel for the delay to asnswer you,
    yes is possible in the video there
   are 2 diferents slide puzzles,
 * at this page you can see it [test page](http://wp.colome.org)
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [Plugin Validation](https://wordpress.org/support/topic/plugin-validation/)
 *  Thread Starter [colome](https://wordpress.org/support/users/colome/)
 * (@colome)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/plugin-validation/#post-3832160)
 * ok!, many thaks for your response!
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [Plugin Validation](https://wordpress.org/support/topic/plugin-validation/)
 *  Thread Starter [colome](https://wordpress.org/support/users/colome/)
 * (@colome)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/plugin-validation/#post-3832074)
 * Yes, of course.

Viewing 6 replies - 1 through 6 (of 6 total)