Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 802
Thierry Lam Avatar asked Sep 28 '09 18:09

Thierry Lam


People also ask

What is the load () method used for in jQuery?

The jQuery load() method is a simple, but powerful AJAX method. The load() method loads data from a server and puts the returned data into the selected element.

Can jQuery be loaded from an external site?

Yes, it's possible, but you'll need 1 line of PHP :) If you only need RSS feeds and you don't mind relying on Google you could use jquery-feeds.


1 Answers

Use $.param(data):

$("#output").load(     "server_output.html?" + $.param({         year: 2009,         country: "Canada"}) ); 
like image 140
Kane Avatar answered Sep 24 '22 00:09

Kane