If a PHP page remains on “Please wait…” indefinitely, first determine whether the browser received the page at all. PHP executes on the server before its generated HTML can be displayed, so a loader embedded in the same slow response cannot appear until that response finishes. Render a lightweight page first, then run the expensive work through an AJAX request that updates the existing page.
Why the loader never appears
With a normal form submission, the browser requests a new document and waits for PHP to generate it. Long database scans, remote requests, or expensive loops delay the complete response. Any loading element in that response is therefore unavailable while PHP is still running.
As an Amazon Associate I earn from qualifying purchases.
A page that has already rendered is different: JavaScript can immediately change the button text, hide the form, and show a spinner while a separate request runs. That distinction explains why a loader may work for an AJAX form but fail during a full-page submit.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Choose the right loading pattern
| Pattern | What the user sees | Advantages | Limitations |
|---|---|---|---|
| Full-page form submit | The current document remains until the destination response arrives. | Smallest implementation and a useful no-JavaScript fallback. | Markup from the destination cannot display while its PHP request is still executing. |
| Separate loading page | A lightweight page appears before navigation to the slow operation. | Simple mental model and clear progress state. | Animation or script behavior can change when the browser starts the next navigation; test the browsers you support. |
| AJAX with an in-page update | The current page stays visible while JavaScript requests data or HTML and injects the result. | The loader can remain visible until success or failure, without leaving the page. | Requires valid, consistently shaped responses and a no-script fallback. |
Recommended fix: render first, then request the slow work
1. Return a fast initial document
Put the form and its waiting indicator in the first response. The page must finish rendering before the indicator can be changed by JavaScript.
#1 Best Overall
<form id="search-form" action="search.php" method="post">
<label>Search <input name="q" required></label>
<button type="submit">Search</button>
</form>
<p id="status" hidden role="status" aria-live="polite">Searching, please wait…</p>
<div id="results"></div>
<noscript>
<p>JavaScript is disabled. Submit the form to load the results as a normal page.</p>
</noscript>
2. Start the AJAX request after submission
Disable the submit control before sending, show the status immediately, and handle both success and failure. The finally block restores the interface even when the request fails.
const form = document.querySelector('#search-form');
const button = form.querySelector('button');
const status = document.querySelector('#status');
const results = document.querySelector('#results');
form.addEventListener('submit', async (event) => {
event.preventDefault();
button.disabled = true;
status.hidden = false;
results.replaceChildren();
try {
const response = await fetch('search.php', {
method: 'POST',
body: new FormData(form),
headers: { 'Accept': 'application/json' }
});
const data = await response.json();
if (!response.ok || !data.ok) {
throw new Error(data.message || 'The request failed.');
}
results.textContent = data.html;
} catch (error) {
results.textContent = error.message;
} finally {
status.hidden = true;
button.disabled = false;
}
});
If the server returns HTML rather than JSON, use await response.text() and inject only trusted, correctly escaped markup. Do not assume a successful HTTP status means the body contains usable data.
3. Make every PHP branch produce one response shape
Malformed or empty responses commonly leave the client stuck at the parsing step. In particular, an early exit before json_encode() sends no JSON at all, producing errors such as “Unexpected end of JSON input.” Validate each condition, assign the error, and encode once at the end.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →<?php
header('Content-Type: application/json; charset=utf-8');
session_start();
$response = ['ok' => false, 'message' => '', 'html' => ''];
$token = $_POST['csrf'] ?? '';
if (!hash_equals($_SESSION['csrf'] ?? '', $token)) {
$response['message'] = 'The security token is invalid or expired.';
} else {
$q = trim((string)($_POST['q'] ?? ''));
if ($q === '') {
$response['message'] = 'Enter a search term.';
} else {
// Perform the slow operation here.
$response['ok'] = true;
$response['html'] = 'Results for: ' . htmlspecialchars($q, ENT_QUOTES, 'UTF-8');
}
}
echo json_encode($response, JSON_UNESCAPED_UNICODE);
The example illustrates the control flow: validation failures and successful work both reach the same output statement. Adapt the authentication, CSRF, database, and escaping details to your application.
Rank #3
Debug the request that starts the waiting message
- Open your browser’s Developer Tools and select the Network panel.
- Submit the form and inspect the request made when the button changes to “Please wait.”
- Check whether it is still pending, ends with an HTTP error, or completes with an empty response body.
- Open the Console and look for JavaScript parsing errors such as
Unexpected end of JSON input. Also inspect the response for PHP warnings. - Open the response body directly. It must be the format the client expects, not a warning, notice, HTML error page, or blank string.
Server-side failures that keep the UI waiting
An empty or malformed response
If JavaScript calls response.json() but PHP emits nothing, emits incomplete JSON, or prints a warning before the JSON, parsing fails. Return JSON on validation errors, CSRF failures, and success paths alike. Log diagnostic details server-side rather than adding arbitrary text to a JSON response.
An early exit before encoding
An expired token branch may set a status and message and then call exit. The browser receives neither value unless the branch encodes and outputs the response first. Prefer one controlled output path, as in the example above.
A missing session timestamp
Do not subtract a missing session value from time(). A helper that returns an empty string when no timestamp exists can trigger PHP’s “A non-numeric value encountered” warning. Check that the value exists and is numeric before arithmetic; otherwise return a normal error response and, if appropriate, create a fresh token timestamp.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Client-side details that prevent a permanent spinner
Always clear the waiting state on both outcomes
Hide the loader and re-enable the submit control in both success and failure handling. A request that fails must not leave the form disabled forever.
Treat whitespace as empty content
When deciding whether a result container has content, trim its text first. For example, jQuery’s $('#content').text().trim() treats a container containing only spaces as empty.
Do not expect the old page to report after navigation
Once a redirect or form navigation leaves the current document, that document no longer controls the destination screen. Show progress before navigation, use a lightweight intermediate page, or keep the operation on the current page with AJAX.
When a full-page submit is still appropriate
Use a normal submit when the operation is short, JavaScript is optional, or accessibility and reliability favor a complete document response. You can change the button label or reveal “Searching, please wait” immediately, but that state only works after the current page has already loaded. It cannot make a slow destination response render sooner.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsThe Bottom Line
A “Please wait…” screen is usually a request-flow problem, not a missing GIF. Verify whether PHP is still running, inspect the Network and Console panels, ensure every server branch returns valid JSON, and move long work into an AJAX request if the loader must remain visible.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




