title: Multiple Ajax requests Colliding
body: <p>I'm building a webshop for a project at university. I have a search bar in header, navigation bar on the left. In both cases I send data with Ajax (from search bar a keyword, from navs a category and subcategory). Ajax response is a PHP script that prints products based on category and subcategory or keyword. At the end of it it prints pagination links and select element for number of products per page. If I submit a keyword or click on a nav, it prints out results fine, but if I then change the page or a number on select element (another Ajax request) , the results default because category/subcategory or keyword are not being sent anymore. This is the code for search bar request:</p>
  
  <pre><code>$("#searchButton").click(function(){ 
      $("#searchBar").blur();
      var keyword=$("#searchBar").val();
  
      $.ajax({
      type:"GET",
      url:"print.php",
      data: { keyword:keyword }
      }).done(function (data){
          $('#content').html(data);
          return false;
      });
  });
  </code></pre>
  
  <p>and this is the code for pagination:</p>
  
  <pre><code>$(document).on("change", "#paginationSelect", function(){
      var productsPerPage=$("#paginationSelect").val();
  
      $.ajax({
      type:"GET",
      url:"print.php",
      data: { productsPerPage:productsPerPage }
      }).done(function (data){
          $('#content').html(data);
          return false;
      });
  });
  </code></pre>
  
  <p>I'm wondering what's the best way to save the data sent by last Ajax request so that I can send it again while changing pagination stuff. Should I change the PHP file or Ajax requests and what's the best way to do it?</p>
  
  <p>Edit:
  This is the PHP file:</p>
  
  <pre><code>&lt;?php
  
  error_reporting(E_ALL ^ E_DEPRECATED);
  
  mysql_connect("localhost", "root", "") or die("Couldn't connect to database.");
  mysql_select_db("webshop") or die("Couldn't select a database.");
  
  mysql_query("SET NAMES 'utf8'");
  mysql_query("SET CHARACTER SET utf8");
  
  if(isset($_GET["category"]) &amp; isset($_GET["subcategory"])){
      $category=$_GET["category"];
      $subcategory=$_GET["subcategory"];
      $query="SELECT * from proizvod where kategorija='".$category."' and podkategorija='".$subcategory."'";
  }
  else if(isset($_GET["keyword"])){
      $keyword=$_GET["keyword"];
      $query="SELECT * from proizvod where ime like '%".$keyword."%'";
  }
  else{
      $query="SELECT * from proizvod";
  }
  
  $result=mysql_query($query);
  
  $numProducts=mysql_num_rows($result);
  if(isset($_GET["productsPerPage"]))$productsPerPage=$_GET["productsPerPage"];
  else if($numProducts&gt;=10) $productsPerPage=10;
  else $productsPerPage=$numProducts;
  
  if(isset($_GET["pageNum"]))$pageNum=$_GET["pageNum"];
  else $pageNum=1;
  if(isset($keyword)) print "&lt;div id=\"keywordMessage\" class=\"col-lg-12\"&gt;Traženi pojam: ".$keyword."&lt;/div&gt;";
  if(mysql_num_rows($result)==0) print "&lt;div class=\"col-lg-12\"&gt;Nema rezultata&lt;/div&gt;";
  for($i=0;$i&lt;($pageNum-1)*$productsPerPage;$i++){
      $row=mysql_fetch_array($result, MYSQL_ASSOC);
  }
  for($i=($pageNum-1)*$productsPerPage;$i&lt;$pageNum*$productsPerPage;$i++){
          $row=mysql_fetch_array($result, MYSQL_ASSOC);
          print("&lt;div class=\"col-lg-6\"&gt;
                      &lt;table class=\"article\"&gt;
                          &lt;tr&gt;&lt;td colspan=\"2\"&gt;&lt;img src=\"images/".$row["id"].".jpg\" class=\"imgArticle\"/&gt;&lt;/td&gt;&lt;/tr&gt;
                          &lt;tr&gt;&lt;td colspan=\"2\"&gt;&lt;b&gt;".$row['ime']."&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
                          &lt;tr&gt;&lt;td&gt;Kategorija: &lt;/td&gt;&lt;td&gt;".$row['kategorija']."&lt;/td&gt;&lt;/tr&gt;
                          &lt;tr&gt;&lt;td&gt;Opis: &lt;/td&gt;&lt;td&gt;".$row['opis']."&lt;/td&gt;&lt;/tr&gt;
                          &lt;tr&gt;&lt;td&gt;Cijena: &lt;/td&gt;&lt;td&gt;".$row['cijena']." kn&lt;/td&gt;&lt;/tr&gt;
                      &lt;/table&gt;
                  &lt;/div&gt;");
  }
  print("&lt;div class=\"col-lg-12\" id=\"paginationControl\"&gt;
          &lt;span class=\"col-lg-4\"&gt;
          Prikazano: ".(($pageNum-1)*$productsPerPage+1)."-".$pageNum*$productsPerPage."/".$numProducts."
          &lt;/span&gt;
          &lt;span  class=\"col-lg-4\" id=\"pageNumbers\"&gt;");
  if($productsPerPage!=0){
      for($i=1;$i&lt;=ceil($numProducts/$productsPerPage);$i++){
          if($i==$pageNum) print($i." &amp;nbsp ");
          else print("&lt;a class=\"pageNumControl\" href=\"#\"&gt;".$i."&lt;/a&gt;");
      }
  }
  print("&lt;/span&gt;
          &lt;span class=\"col-lg-4\"&gt;Proizvoda po stranici: 
              &lt;select id=\"paginationSelect\"&gt;
                  &lt;option value=\"10\" "); if($productsPerPage==10){ print("selected");} print("&gt;10&lt;/option&gt;
                  &lt;option value=\"20\" "); if($productsPerPage==20){ print("selected");} print("&gt;20&lt;/option&gt;
                  &lt;option value=\"30\" "); if($productsPerPage==30){ print("selected");} print("&gt;30&lt;/option&gt;
                  &lt;option value=\"50\" "); if($productsPerPage==50){ print("selected");} print("&gt;50&lt;/option&gt;
              &lt;/select&gt;
              &lt;/span&gt;
          &lt;/div&gt;");
  mysql_free_result($result);
  </code></pre>
  
  <p>?></p>