Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to send a get request with params without ajax

Tags:

jquery

I want to send an ordinary get request which replaces the entire page just like an ordinary get request but using jQuery if possible. I also need to send 2 parameters in the request.

I don't want to replace some content in my document with the result, the result is the complete document.

The code here still sent an ajax request and my page was not refreshed with the response..

$.get({
       url: '/swap_games', 
       data: { source: sourceElem, target: targetElem } 
});
like image 885
markhorrocks Avatar asked Oct 08 '11 03:10

markhorrocks


People also ask

Can you send data in a GET request?

Can I send data using the HTTP GET method? No, HTTP GET requests cannot have a message body. But you still can send data to the server using the URL parameters. In this case, you are limited to the maximum size of the URL, which is about 2000 characters (depends on the browser).

Is Ajax request GET or POST?

post() methods provide simple tools to send and retrieve data asynchronously from a web server. Both the methods are pretty much identical, apart from one major difference — the $. get() makes Ajax requests using the HTTP GET method, whereas the $. post() makes Ajax requests using the HTTP POST method.

Can we use Ajax without URL?

URL is not required, if you make call to current page. (...) In the second form, the URL is specified in the options parameter, or can be omitted in which case the request is made to the current page. Save this answer.


1 Answers

jQuery has a load() method that does this for you.

.load( url, [data,] [complete(responseText, textStatus, XMLHttpRequest)] )

Example as follows:

$('html').load('/swap_games', data: { source: sourceElem, target: targetElem } );

Or with a callback:

$('html').load('/swap_games', data: { source: sourceElem, target: targetElem }, function() {
   alert('load complete callback');
});

More info here

like image 85
Gabe Avatar answered Nov 15 '22 06:11

Gabe