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 }
});
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).
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With