Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to make AJAX call that doesn't return?

Is it possible to send an jQuery.ajax call or equivalent without any sort of response? I want to trigger something on the server as I leave the page with the onbeforeunload command, but it's not something I need to feedback to the client, so I just want to send off the command and not wait for a response.

Is that possible?

like image 885
Paul Tomblin Avatar asked Sep 20 '12 18:09

Paul Tomblin


People also ask

How do you make AJAX call fail?

The function specified by the ajaxError() function is called when the request fails or generates the errors. We can use the fail() callback function as well on the JavaScript promise object( the jqXHR object return by the $. ajax() function) to run the specific function on the ajax request fail.

How can AJAX execution be stopped after success?

// Perform a simple Ajax request var req = $. ajax({ type: "GET", url: "/user/list/", success: function(data) { // Do something with the data... // Then remove the request. req = null; } }); // Wait for 5 seconds setTimeout(function(){ // If the request is still running, abort it. if ( req ) req.

Does an AJAX request return a promise?

ajax returns, which is a jqXHR object that conforms to the promise interface. If there is a failure, the outer fail function is invoked. The outer fail function is also invoked if the processData function fails. When both the getData and processData functions are successful, the outer done method is invoked.

What is timeout AJAX call?

ajax({ timeout : value }); Parameters – timeout – This is an optional option. It specifies the timeout for the request in terms of milliseconds. The default value is 0.


1 Answers

Every request has a response. Even if the server throws an error a response is coming back with the error.

You can ignore the response if you like to just don't add a success callback.

$.ajax({
    url: "theURL",
    data: theData
});
like image 143
gdoron is supporting Monica Avatar answered Oct 27 '22 09:10

gdoron is supporting Monica