title: Automatically cancelling jqgrid request
body: <p>I'm aware of this answer: <a href="https://stackoverflow.com/questions/4016583/how-do-i-add-a-cancel-button-to-my-jqgrid/4017022#4017022">How do I add a cancel button to my jqgrid?</a>, and I'm attempting to implement something similar, although without a button to trigger the cancel. Iv'e got a grid that loads on page load (a search that by default loads with no criteria) and I'd like to be able to cancel that default empty criteria search when the user actually executes a search with criteria. Since I don't need a button I'm trying to simplify the solution by merely keeping track of the xhr request in the loadBeforeSend method, and abort that xhr if it is not null as I load the grid. Code:</p>
  
  <pre><code>var gridXhr;
  function getGridData() {
      var searchParms = ...;
      var colHeaders = [...];
      var colDefinitions = [...];
      if (gridXhr != null) {
          alert(gridXhr.readyState);
          gridXhr.abort();
          gridXhr = null;
      }
      $('#grid').jqGrid('GridUnload');
      $('#grid').jqGrid({
          defaults: {...},
          autowidth:true,
          url: "&lt;%= Page.Request.Path %&gt;/ExecuteSearch",
          mtype: 'POST',
          ajaxGridOptions: { contentType: "application/json" },
          postData: searchParms,
          datatype: "json",
          prmNames: {
              nd: null,
              rows: null,
              page: null,
              sort: null,
              order: null
          },
          jsonReader: {
              root: function (obj) { return obj.d; },
              page: function (obj) { return 1; },
              total: function (obj) { return (obj.d.length / 20); },
              records: function (obj) { return obj.d.length; },
              id: 'CatalogID',
              cell: '',
              repeatitems: false
          },
          loadonce: true,
          colNames: colHeaders,
          colModel: colDefinitions,
          caption: "Search Results",
          pager: 'searchPaging',
          viewrecords: true,
          loadBeforeSend: function (xhr) {
              gridXhr = xhr;
          },
          loadError: function (xhr, status, error) {
              gridXhr = null;
              if (error != 'abort') {
                  alert("Load Error:" + status + "\n" + error);
              }
          },
          loadComplete: function() {
              gridXhr = null;
          },
          multiselect: &lt;%= this.MultiSelect.ToString().ToLower() %&gt;,
          multiboxonly: true
      }).setGridWidth(popWidth);
  }
  </code></pre>
  
  <p>The problem I'm having is that subsequent executions of the jqGrid don't work. The loadError function is triggered, with an error (3rd parameter) of "abort." Do I need to do something more/different with the loadBeforeSend as done in the other answer?</p>
  
  <p>Also, Oleg mentioned in his sample code <code>myGrid[0].endReq();</code> and I can find no mention of that in the documentation - does that function exist?</p>