How can I use jQuery "load" to perform a GET request with extra parameters?

Thierry Lam picture Thierry Lam · Sep 28, 2009 · Viewed 28.2k times · Source

I'm reading the jQuery load documentation and it mentions that I can use load to perform a GET request by passing in extra parameters as a string. My current code with my parameters as key/value pair is:

$("#output").load(
    "server_output.html",
    {
        year: 2009,
        country: "Canada"
    }
);

The above works fine but it's a post request. How can I modify the above to perform a GET request while still using load?

Answer

Kane picture Kane · Sep 28, 2009

Use $.param(data):

$("#output").load(
    "server_output.html?" + $.param({
        year: 2009,
        country: "Canada"})
);