title: How to make an ajax call with parameters into Wordpress site
body: <p>I have a simple web with an ajax call with parameters that works fine alone:
  <a href="http://www.colome.org/utils/" rel="nofollow noreferrer">http://www.colome.org/utils/</a></p>
  
  <p>This is the sample code:</p>
  
  <p><strong>index.html:</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang=en&gt;
  &lt;head&gt;
      ...
      &lt;script src="codi.js"&gt;&lt;/script&gt;
      ...
  &lt;/head&gt;
  &lt;body&gt;
  &lt;section id="main"&gt;
      &lt;table id="tng" class="datagrid"&gt;
          &lt;tbody&gt;
          &lt;/tr&gt;&lt;tr&gt;
              &lt;td width="50%" align="right"&gt;&lt;b&gt;Host or IP:&lt;/b&gt;&lt;/td&gt;
              &lt;td&gt;&lt;input  id="ip" size="20" value="" &gt;&lt;/td&gt;
              &lt;td&gt;&lt;button type="button" onclick="Ping()"&gt;Ping&lt;/button&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;/tbody&gt;
      &lt;/table&gt;
    ...
  &lt;/section&gt;  
  &lt;h3 id="notification"&gt;&lt;/h3&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I created a function "<strong>Ping</strong>" inside <strong>codi.js</strong> that makes the ajax call</p>
  
  <p><strong>codi.js:</strong></p>
  
  <pre><code>function Ping()
  {
      $("#image").show();
          var ip=document.getElementById('ip');
      $.ajax({
          type: "POST",
          url: "http://...../ping.php",
          cache: false,
          //contentType: "application/json; charset=utf-8",
          //dataType: "json",
          data: {"ip" : ip.value}, 
          success: onSuccesPing,
          error: onErrorPing,
          crossDomain:true
      });
  
  }
  function onSuccesPing(data,status)
  {
     document.getElementById("notification").innerHTML=data;
  }
  function onErrorPing(data,status)
  {
     document.getElementById("notification").innerHTML=data.responseText);
  }
  </code></pre>
  
  <p>And finally the <strong>ping.php</strong> code, very simple:</p>
  
  <pre><code>&lt;?php
  $ip =   $_POST["ip"];
  exec("ping -c 3 ".$ip." 2&gt;&amp;1", $output, $status);
  foreach ($output as $key =&gt; $value) {
      echo ($value.'&lt;br&gt;');
  }
  
  ?&gt;
  </code></pre>
  
  <p>I was trying to integrate this code to my wordpress website, like the example below:
  <a href="https://stackoverflow.com/questions/17710728/how-to-load-ajax-in-wordpress">For example this way</a>
   but I don't know how to pass parameters to the ajax call, please can you help me? thanks.</p>