title: jQuery Ajax Post with data
body: <p>why it isn't working. Am trying to call a php file when onclick of a button occurs with some parameters. It is getting executed till alert statement in jsfile.js. After that the ajax part is not getting executed.. Help me out.. Thanks in advance..</p>
  
  <p><strong>main.html</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;&lt;/title&gt;
  
  &lt;script src="jsfile.js"&gt;&lt;/script&gt;
  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
          &lt;button onclick="cart(0)"&gt; hi &lt;/button&gt;
          &lt;p id="disp"&gt;&lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>jsfile.js</strong></p>
  
  <pre><code>function cart(id1)
  {
  
      var id=id1;
      alert("enterd "+id);
      document.getElementById("disp").innerHTML ="hi";
          $.ajax({
          url:"/add.php ",
          type:"POST",
  
          data:{
            item_id: id,
          },
          success:function(response) {
            //document.getElementById("total_items").value=response;
           document.getElementById("disp").innerHTML =response;
         },
         error:function(){
          alert("error");
         }
  
        });
  
  }
  </code></pre>
  
  <p><strong>add.php</strong></p>
  
  <pre><code>&lt;?php
      if(isset($_POST['item_id']) &amp;&amp; !empty($_POST['item_id'])){
      //if(count($_POST)&gt;0)
          echo "success";
          exit();
      }
  ?&gt;
  </code></pre>