title: Send php response to ajax and display result in div
body: <p>I have made a simple form through which i can search the keywords and find the related output from database dynamically. The code works perfect without AJAX . But now i have applied some AJAX code to get the response on same page within a div named <code>coupon</code>. I am unable to get the response. I don't know where am i doing wrong. Any suggestions please. Here is the complete code.</p>
  
  <p><strong>form</strong></p>
  
  <pre><code>&lt;form action="" id="search_form" method="POST"&gt;
  &lt;p&gt;&lt;input name="query" autocomplete="off" id="list_search" type="search" required class="list_search" /&gt;&lt;/p&gt;
  &lt;p align="center"&gt;&lt;input type="submit" id="click" name="click" class="but" value=" search"  /&gt;&lt;/p&gt;
  &lt;/form&gt;
  &lt;div class="coupons"&gt;&lt;/div&gt;
  </code></pre>
  
  <p><strong>AJAX</strong></p>
  
  <pre><code>$("document").ready(function(){
         // $(".but").click(function(event){  // here
          $("#search_form").submit(function (event) {
  
           {
              event.preventDefault();
  
             var myData={ query: $( 'input[name="query"]' ).val() };
                  $.ajax({
                      url: 'result.php',
                      data: myData,
                      type: 'post',
                      dataType: "html",
                      success: function(result){
                          //console.log(result);
                          $('.coupons').html(result);
                      },
                      error: function() {
                          alert('Not OKay');
                      }
                  });
          });
      });
  </code></pre>
  
  <p><strong>result.php</strong></p>
  
  <pre><code> $keyword = mysqli_real_escape_string($con,$_REQUEST['query']); // always escape
   $keys = explode(" ", $keyword);
   $sql="SELECT  c.* , sc.* , sm.* ,ca.* from store_category sc INNER JOIN store_manufacture sm ON sm.sm_id=sc.store_id INNER JOIN categories ca ON ca.cat_id=sc.cat_id INNER JOIN coupons c on c.c_sc_id=sc.sc_id WHERE c.c_name LIKE '%$keyword%' OR sm.sm_brand_name LIKE '%$keyword%' OR ca.cat_name LIKE '%$keyword%' OR c.c_description LIKE '%$keyword%'";
  
  foreach ($keys as $k) {
  
      $sql.="OR c.c_name LIKE '%$k%' OR sm.sm_brand_name LIKE '%$k%' OR ca.cat_name LIKE '%$k%' OR c.c_description LIKE '%$k%'";
  }
  
  $result = mysqli_query($con, $sql);
  $count=mysqli_num_rows($result);
  if($count!=0) {
      while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
  
         $res=$row['c_name'].$row['c_description'];
          echo json_encode($res);
      }
  }
  else
  {
      echo "no result";
  }
  </code></pre>