title: Is there a way to prevent Enter key from returning a response in json from another page? Codeigniter Ajax
body: <p>I am using ajax for my operations <code>Create</code> and <code>Update</code></p>
  
  <p>I can already create and update, but if I press or hit <strong>Enter key</strong> then this shows from another page which is kinda not look good to see, and it suddenly also create blank data after hitting <strong>Enter</strong> key.</p>
  
  <pre><code>{"success":false,"type":"update"}
  </code></pre>
  
  <p>For visual representation, here it what it looks like after hitting the <strong>Enter key</strong> on input fields</p>
  
  <p><a href="https://i.stack.imgur.com/HVbHQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HVbHQ.png" alt="enter image description here"></a></p>
  
  <p>this is what my input is in my View</p>
  
  <pre><code> &lt;input type="text" name="group[]" id="group" placeholder="Enter your Choice" class="form-control" /&gt;
  </code></pre>
  
  <p>in my Controller </p>
  
  <pre><code>public function addGroup(){
      $result = $this-&gt;group_model-&gt;addGroup();
      $msg['success'] = false;
      $msg['type'] = 'add';
      if($result){
          $msg['success'] = true;
      }
      echo json_encode($msg);
  }
  
  
  public function updateGroup(){
      $result = $this-&gt;group_model-&gt;updateGroup();
      $msg['success'] = false;
      $msg['type'] = 'update';
      if($result){
          $msg['success'] = true;
      }
      echo json_encode($msg);
  }
  </code></pre>
  
  <p>And in Model</p>
  
  <pre><code>public function updateGroup(){
      $id = $this-&gt;input-&gt;post('txtId');
      $field = array(
      'group_name'=&gt;$this-&gt;input-&gt;post('group')
      );
      $this-&gt;db-&gt;where('id', $id);
      $this-&gt;db-&gt;update('groups', $field);
      if($this-&gt;db-&gt;affected_rows() &gt; 0){
          return true;
      }else{
          return false;
      }
  }
  
  
  
  public function addGroup(){
      $field = array(
          'group_name'=&gt;$this-&gt;input-&gt;post('group'),
      );
      $this-&gt;db-&gt;insert('groups', $field);
      if($this-&gt;db-&gt;affected_rows() &gt; 0){
          return true;
      }else{
          return false;
      }
  }
  </code></pre>
  
  <blockquote>
    <p>Ajax</p>
  </blockquote>
  
  <pre><code>$('#btnSave').click(function(){
          var url = $('#myForm').attr('action');
          var data = $('#myForm').serialize();
          //validate form
          var group = document.getElementById('group').value;
  
          if(group.replace(/\s/g, "").length &lt;=0 ) {
              swal("Submission fail!", "Enter the required field", "error");
              return false;
          }
  
              $.ajax({
                  type: 'ajax',
                  method: 'post',
                  url: url,
                  data: data,
                  async: false,
                  dataType: 'json',
                  success: function(response){
                      if(response.success){
                          $('#myModal').modal('hide');
                          $('#myForm')[0].reset();
                          if(response.type=='add'){
                              var type = 'added'
                          }else if(response.type=='update'){
                              var type = 'updated'
                          }
  
                          swal("Success!", "You delete a Question!", "success");                          
                          showGroups();
                      }else{
                          alert('Error');
                      }
                  },
                  error: function(){
                      alert('Could not add data');
                  }
              });
  
      });
  </code></pre>