title: How to pass parameters in GET requests with jQuery
body: <p>How should I be passing query string values in a jQuery Ajax request? I currently do them as follows but I'm sure there is a cleaner way that does not require me to encode manually.</p>
  
  <pre><code>$.ajax({
      url: "ajax.aspx?ajaxid=4&amp;UserID=" + UserID + "&amp;EmailAddress=" + encodeURIComponent(EmailAddress),
      success: function(response) {
          //Do Something
      },
      error: function(xhr) {
          //Do Something to handle error
      }
  });
  </code></pre>
  
  <p>I’ve seen examples where query string parameters are passed as an array but these examples I've seen don't use the <code>$.ajax()</code> model, instead they go straight to <code>$.get()</code>. For example:</p>
  
  <pre><code>$.get("ajax.aspx", { UserID: UserID , EmailAddress: EmailAddress } );
  </code></pre>
  
  <p>I prefer to use the $.ajax() format as it's what I’m used to (no particularly good reason - just a personal preference).</p>
  
  <p><strong>Edit 09/04/2013:</strong></p>
  
  <p>After my question was closed (as "Too Localised") i found a related (identical) question - with 3 upvotes no-less (My bad for not finding it in the first place):</p>
  
  <p><a href="https://stackoverflow.com/questions/3066070/using-jquery-to-make-a-post-how-to-properly-supply-data-parameter">Using jquery to make a POST, how to properly supply &#39;data&#39; parameter?</a></p>
  
  <p>This answered my question perfectly, I found that doing it this way is much easier to read &amp; I don't need to manually use <code>encodeURIComponent()</code> in the URL or the DATA values (which is what i found unclear in bipen's answer). This is because the <code>data</code> value is encoded automatically via <a href="http://api.jquery.com/jQuery.param/" rel="noreferrer"><code>$.param()</code></a>). Just in case this can be of use to anyone else, this is the example I went with:</p>
  
  <pre><code>$.ajax({
      url: "ajax.aspx?ajaxid=4",
      data: { 
          "VarA": VarA, 
          "VarB": VarB, 
          "VarC": VarC
      },
      cache: false,
      type: "POST",
      success: function(response) {
  
      },
      error: function(xhr) {
  
      }
  });
  </code></pre>