jQuery Ajax Call Without Waiting For Response in PHP


AJAX stands for Asynchronous JavaScript and XML. AJAX is an advanced javascript technique for creating faster and more interactive web apps with the help of HTML, CSS, and JavaScript.

Recently, I need to make an ajax call without waiting for a response and I have found some examples on the internet but none were clearly explained. so, I decided to write a blog post for jQuery ajax call without waiting for a response in PHP.

Let’s, See the example


In the above, we have included one jquery and added one button for ajax calls. When you click on the “File Write Now” button ajax call will fire on ajaxBack.php

2) ajaxBack.php


We have set the above variables to Ignore user aborts and allow the script to run forever.

header(‘Connection: close’);
After sending the response message, the connection gets closed. you need to include it in the header if you want your connection to close.

header(‘Content-Length: ‘.ob_get_length());
HTTP Content-Length header is used to indicate the size of data in the body of the request.

This function will delete the topmost output buffer and turn this output buffer off.

ob_flush passes the current content to the upper layer and flushes output buffers you created with a function like ob_start

flushes buffered output of the PHP script itself to its caller.

Now, our loop run 20 times and write one text file with test data. in between writing the data you can close your browser tab. still, data should be written in a txt file. The response will send instantly even background process is running.

So, in the jQuery Ajax Call Without Waiting For Response in PHP article, our main motive is we need an instant response without waiting for script execution.

I hope it helped you to fix error 1292 – Incorrect date value: ‘0000-00-00’ for column ‘date’. Please let us know in the comment section if you have any concerns.

Thank You!