Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending normal request in jquery ( not ajax)

Is there any method in jquery like $.post , $.ajax etc which works like a normal form submission. I know about .submit() but it requires a form element , can we send a normal request without a form element in jquery?

like image 308
Gaurav Avatar asked May 31 '12 14:05

Gaurav


People also ask

Are AJAX requests HTTP requests?

Ajax. Ajax is the traditional way to make an asynchronous HTTP request. Data can be sent using the HTTP POST method and received using the HTTP GET method.

Is AJAX request GET or POST?

GET vs POST in AJAX callsUnless you are sending sensitive data to the server or calling scripts which are processing data on the server it is more common to use GET for AJAX calls. This is because when using XMLHttpRequest browsers implement POST as a two-step process (sending the headers first and then the data).

What type of request is AJAX?

ajax() method allows you to send asynchronous http requests to submit or retrieve data from the server without reloading the whole page. $. ajax() can be used to send http GET, POST, PUT, DELETE etc. request.

Does AJAX return a promise?

ajax returns a promise object, so that we don't have to pass a callback function.


2 Answers

window.location.href = '/controller/action?foo=bar';
like image 57
Darin Dimitrov Avatar answered Oct 19 '22 04:10

Darin Dimitrov


You can submit without a form using $.ajax(). Further, to make it behave like a normal form would, set the async property to false.

$.ajax({
    url:   "/controller/action",
    data:  {'foo':'bar'},
    async: false
});

This will result in you being sent to:

"/controller/action?foo=bar"
like image 28
Sampson Avatar answered Oct 19 '22 05:10

Sampson