Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Im not sure how to actually access the post variables in the url</p> </blockquote> <p>First off, if they're in the URL, they're <code>GET</code> variables, not <code>POST</code> variables (which are in the body of a request sent <em>to</em> the server). Specifically, they're values on the <em>query string</em>.</p> <p>You can access the query string via <code>location.search</code>. Unfortunately, it is as it appears in the address bar, rather than nicely parsed out for you, but there are plug-ins you can use that will handle parsing it out for you, <a href="https://github.com/allmarkedup/jQuery-URL-Parser" rel="nofollow">like this one</a> which would give you access to your <code>pg2</code> variable like this:</p> <pre><code>var pg2 = $.url(location).param('pg2'); </code></pre> <p>That <code>pg2</code> variable will be <code>undefined</code> if there is no matching parameter on the query string.</p> <p>That's just one example, there are several query string / URL parsing plug-ins available, or of course you can roll your own. Here's one I did a couple of years ago:</p> <pre><code>/** * Split up the given string (for instance, window.location.search) into component parts. * * @param str The string * @param The component parts as keys on an object; if the query string has repeated entries, * that key's value will be an array; a key with no value is present with the value * `undefined`. */ $.splitQueryString = splitQueryString; function splitQueryString(str) { var entries, parts, result, entryIndex, key, newVal, oldVal; // We return the result as an object result = {}; // Skip a leading ? if any if (str.charAt(0) === '?') { str = str.substring(1); } // Strip anything after the hash symbol index = str.indexOf('#'); if (index &gt;= 0) { str = str.substring(0, index); } // decodeURIComponent won't do '+' =&gt; ' ', so do it str = str.replace(/\+/g, ' '); // Split into entries entries = str.split('&amp;'); for (index = 0; index &lt; entries.length; ++index) { parts = entries[index].split('='); key = decodeURIComponent(parts[0]); newVal = parts[1]; if (typeof newVal !== 'undefined') { newVal = decodeURIComponent(newVal); } if (key in result) { oldVal = result[key]; if ($.isArray(oldVal)) { oldVal.push(newVal); } else { result[key] = [oldVal, newVal]; } } else { result[key] = newVal; } } // Done return result; } </code></pre> <p>Usage:</p> <pre><code>var pg2 = $.splitQueryString(location.search).pg2; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload