title: auto submit form on pageload using AJAX and get html type result?
body: <p>I'm trying to autosubmit a form on page load using ajax and then get the HTML (a bunch of divs that will be echo-ed on the AJAX URL) back to my AJAX page.</p>
  
  <p>first off, my code auto submits the form but it will ignore the AJAX call so the user will be taken to the form's action page.</p>
  
  <p>also, if I remove the auto submit code from my AJAX code and submit the form manually via the submit button I get nothing back from the AJAX URL page!</p>
  
  <p><strong>This is my entire code:</strong></p>
  
  <pre><code>window.onload = function(){
  document.forms['myformR'].submit()  
  
  
    // this is the id of the form
      $("#myformR").submit(function() {
  
          var url = "results.php"; // the script where you handle the form input.
  
          $.ajax({
                 type: "POST",
                 url: url,
                  dataType: "html", //expect html to be returned                
                  success: function (response) {
                      $("#prores").html(response);
  
  
                  }
               });
  
          return false; // avoid to execute the actual submit of the form.
      });
  
  }
  </code></pre>
  
  <p>any advise would be appreciated.</p>
  
  <p>EDIT, THIS IS MY ajax PHP URL page:</p>
  
  <pre><code>&lt;?php
  session_start();
  ?&gt;
  &lt;?php
  include "config/connect.php";
  $searchList = "";
  $clause = " WHERE ";//Initial clause
  $sql="SELECT *
  FROM `yt`
  INNER JOIN `ATTRIBUTES` ON yt.subcats=ATTRIBUTES.type";//Query stub
  if(isset($_POST['submit'])){
      if(isset($_POST['keyword'])){
          foreach($_POST['keyword'] as $c){
              if(!empty($c)){
                  ##NOPE##$sql .= $clause."`".$c."` LIKE '%{$c}%'";
                  $sql .= $clause . " (ATTRIBUTES.sizes LIKE BINARY '$c' OR ATTRIBUTES.colors LIKE BINARY '$c' OR ATTRIBUTES.type LIKE BINARY '$c')";
                  $clause = " OR ";//Change  to OR after 1st WHERE
              }
          }
          $sql .= " GROUP BY yt.id ";
          //print "SQL Query: $sql&lt;br /&gt;"; //&lt;-- Debug SQl syntax.
          // Run query outside of foreach loop so it only runs one time.
          $query = mysqli_query($db_conx, $sql);
          //var_dump($query); //&lt;-- Debug query results.
          // Check that the query ran fine.
          if (!$query) {
              print "ERROR: " . mysqli_error($db_conx);
          } else {
              // Use $query inside this section to make sure $query exists.
              $productCount = mysqli_num_rows($query);
              $i=0; // count the output amount
              if ($productCount &gt; 0) {
                  while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){
          $sizesOption ="";
          $colorOption ="";
               $id = $row["id"];
               $product_name = $row["product_name"];
               $details = $row["details"];
               $details = preg_replace("/\\\\r\\\\n/", "", $details);
               $price = $row["price"];
               $category = $row["category"];
               $manu = $row["manu"];
               $sizez = $row["sizez"];
               $colours = $row["colours"];
               $colours = preg_replace('/\.$/', '', $colours);
               $sizez = preg_replace('/\.$/', '', $sizez); //Remove dot at end if exists
               $array = explode(',', $sizez);
               $arrayC = explode(',', $colours); //split string into array seperated by ','
               foreach($array as $value) //loop over values
               {
                   //echo $value . PHP_EOL; //print value
                   $sizesOption .='&lt;option&gt;'.$value.'&lt;/option&gt;';
                }
              foreach($arrayC as $valueC) //loop over values
               {
                   //echo $value . PHP_EOL; //print value
                   $colorOption .='&lt;option&gt;'.$valueC.'&lt;/option&gt;';
                }
                     $searchList .= '&lt;div align="center" class="mypro" style="position:relative; width:270px; height:470px; border:solid 1px #CCC; margin:10px; float:left; overflow:hidden; padding:5px;"&gt;
  
  &lt;a class="overlay" href="product.php?id='.$id.'"&gt;&lt;/a&gt;
  
  &lt;!--&lt;a class="overlayBtns" href=""&gt;Quick View&lt;/a&gt;--&gt;
  
  &lt;div class="overlayAdd"&gt;
  
  
  
              &lt;a style="font: bold 11px Arial;
    text-decoration: none; background-color: #FFF; color: #333333; padding: 10px; border:none; border-radius:4px; width:120px; height:30px;" id="go" rel="leanModal" name="test" href=".test'.$id.'"&gt;Qick View &lt;i style="color:#000; font-size:18px;" class="fa fa-eye"&gt;&lt;/i&gt;&lt;/a&gt;
  
  
  
             &lt;div  style="display:none; display:none; width:580px; height:auto; background-color:#FFF; border-radius:4px; padding:12px;" class="test'.$id.'"&gt;
  
  
             &lt;h2&gt;'.$product_name.'&lt;/h2&gt;
  
           &lt;p style="text-align:left;"&gt;'.$details.'&lt;/p&gt;
           &lt;form id="form'.$id.'" class="form1" name="form1" method="post" action="cart.php"&gt;
           &lt;p&gt;
           &lt;p style="text-align:left; font-weight:bold;"&gt;Size&lt;/p&gt;
           &lt;select id="sizeSelect"  name="sizeSelect" style=""&gt;
           '.$sizesOption.'
           &lt;/select&gt;
  
  
           &lt;p style="text-align:left; font-weight:bold;"&gt;Colour&lt;/p&gt;
           &lt;select id="colorSelect" name="colorSelect" style=""&gt;
           '.$colorOption.'
           &lt;/select&gt;
  
           &lt;/p&gt;
          &lt;p style="text-align:left; font-weight:bold; width:100px; float:left;"&gt;Quantity&lt;/p&gt; 
               &lt;input min="1" type="number" id="quantity" name="quantity" value="1" /&gt;
          &lt;/p&gt; 
          &lt;p&gt;
          &lt;input type="hidden" name="pid" id="pid" value="'.$id.'" /&gt;
          &lt;input type="hidden" name="moneyPrice" id="moneyPrice" class="moneyPrice" value="" /&gt;
          &lt;input type="hidden" name="moneyCurreny" id="moneyCurreny" class="moneyCurreny" value="" /&gt;
          &lt;input style="background-color:#000; color:#FFF;" type="submit"  value="ADD TO BASKET" /&gt;
  
        &lt;/form&gt;&lt;/p&gt;
        &lt;br&gt;&lt;br&gt;
        &lt;a href="product.php?id='.$id.'"&gt;View Item Full Details&lt;/a&gt;&lt;br&gt;&lt;br&gt;
  
  &lt;div class="share-buttons" data-url="http://enzua.com/product.php?id='.$id.'" data-text="http://enzua.com/product.php?id='.$id.'"&gt;&lt;/div&gt;
  
          &lt;/div&gt;&lt;/div&gt;
  
  
  &lt;img width="100%" src="product_images/'.$id.'Image1.jpg" alt=""  /&gt;
  
  
  &lt;p style="padding:2px;"&gt;'.$product_name.'&lt;/p&gt;
  &lt;p style="padding:2px;"&gt;'.$manu.'&lt;/p&gt;
  
      &lt;div style="padding:5px;" class="price"&gt;
  
        &lt;div class="prod-price"&gt;&lt;span class=money&gt;£'.$price.'.00&lt;/span&gt;&lt;/div&gt;
      &lt;/div&gt;
  
  &lt;/div&gt;';
                  }
              }
          }
      }
  }
  
  ?&gt;
  &lt;?php 
  echo $searchList;
  exit(); 
  ?&gt;
  </code></pre>
  
  <p>AND THIS IS MY HTML FORM:</p>
  
  <pre><code>    &lt;form class="myformR" id="myformR" name="myformR" method="post" action="results.php"&gt;
  
      &lt;input type="hidden" name="keyword[]" value="dress" /&gt;
  
      &lt;input id="smt" type="submit" value="submit" name="submit" /&gt;
  
      &lt;/form&gt;
  &lt;div id="prores"&gt;&lt;/div&gt;
  </code></pre>