title: Why is my jQuery Ajax json array data getting repeated?
body: <p>Not sure why this is happening maybe I put codes inside one another - or maybe totally different issue. Looking for expertise in this situation. I am trying a basic example, where select data is populated from the database:</p>
  <pre><code>      &lt;div class=&quot;col-md-4 mb-3&quot;&gt;
          &lt;label for=&quot;producer&quot;&gt;Select Producers&lt;/label&gt;
          &lt;?php if ($data): ?&gt;
          &lt;select class=&quot;custom-select d-block w-100&quot; name=&quot;producer[]&quot; id=&quot;producer&quot; required=&quot;&quot; size=&quot;5&quot; multiple&gt;
              &lt;?php foreach($data as $row): ?&gt;
                  &lt;option value=&lt;?php echo $row['Id'] ?&gt; &gt;&lt;?= $row['producer_name'] ?&gt;&lt;/option&gt;
              &lt;?php endforeach ?&gt;
          &lt;/select&gt;
          &lt;?php else: ?&gt;
              No data found
          &lt;?php endif ?&gt;
          &lt;button class=&quot;btn btn-danger btn-sm&quot; type=&quot;submit&quot; id=&quot;del_producer&quot;&gt;Delete&lt;/button&gt;
          &lt;div id=&quot;asd&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
  </code></pre>
  <p>There is a button which will send the multiple selected data to another php page through ajax. Here is the code.</p>
  <pre><code>$('#producer').on('click', function(event){
  var prodId=' ';
  prodId = $(this).val();
  var jsonString = JSON.stringify(prodId);
  document.getElementById(&quot;asd&quot;).innerHTML = jsonString;
  if (prodId!=&quot;&quot;){
    $(&quot;#del_producer&quot;).click(function(){
      $(&quot;#del_producer&quot;).attr(&quot;disabled&quot;, &quot;disabled&quot;);
      $.ajax({
              url: &quot;delete.php&quot;,
              type: &quot;POST&quot;,
              data: {data : jsonString},
              cache: false,
              success: function(result){
                  $(&quot;#del_producer&quot;).removeAttr(&quot;disabled&quot;);
                  prodId = '';
                  alert(result);
                  console.log(result);
              }
          });
    });
  }
      else{
          alert('Please select producer to delete!');
      }
  });
  </code></pre>
  <p>#asd is just checking if the values selected are correct before sending. And yes it is correct. Now my php file looks like this:</p>
  <pre><code>    $data = json_decode(stripslashes($_POST['data']));
      $array = implode(',', $data);
      echo $array;
  </code></pre>
  <p>Yes just three lines to get return what I sent.
  Now to the problem: I am sending 3 id values [2,3,5] it is shown such in #asd as well. Now when I click the button - the response I am receiving is [2] , [2,3] , [2,3,5] - three responses. It should be something I am missing. Can someone please point it out. I need it to be [2,3,5] as I am sending.</p>