Tool not showing results after user submits form
-
Hi everyone,
I’ve built a small lookup tool on my WordPress site where users can enter an account number and see some related information (like billing amount, due date, etc.).
It was working fine for a few days, but suddenly the form stopped displaying the results.
- The form still submits
- The page reloads, but no data shows
- When I check in the browser console, I see an error related to
fetchor JSON parse
I’m using a shortcode to call the PHP function that sends a request to an external API and returns the data.
Does anyone know why this might happen? Could it be a caching issue, SSL problem, or maybe WordPress blocking the API call?
I’ve already tried disabling caching and checked the API key both seem fine.
Any ideas or troubleshooting steps would be really helpful
-
This usually happens when the external API returns something other than valid JSON (for example, HTML with an error message).
You can confirm this by adding some basic logging to your PHP code:
$response = wp_remote_get( $api_url ); if ( is_wp_error( $response ) ) { error_log( $response->get_error_message() ); } else { $body = wp_remote_retrieve_body( $response ); error_log( $body ); }Then check your
debug.logfile to see what the API actually returned.
If you see HTML or a “403 Forbidden,” the issue isn’t with WordPress it’s the API response itself. -
I had a similar issue on one of my client sites. It turned out that the security plugin (Wordfence) was blocking outgoing requests from PHP to external domains.
Try temporarily disabling any firewall or security plugin, then test again.
If it works, whitelist the external API domain under Wordfence → All Options → Firewall Whitelist.Also, make sure your hosting provider allows outbound cURL connections some shared hosts block these for security reasons.
-
-
Glad you got it mostly fixed — one more tip: sometimes the issue is the way the front-end JavaScript handles the response before the PHP even returns it. I had the same problem where
response.json()threw an error because the server returned an empty string for certain account numbers.I solved it by adding a safe-check in the JS and returning a small JSON error object from PHP when data is missing. That way the front end never tries to parse invalid JSON.
Example of the pattern I use (very small):
fetch('/wp-admin/admin-ajax.php?action=lookup&number=12345') .then(res => res.text()) // read as text first .then(txt => txt ? JSON.parse(txt) : { error: 'no data' }) .then(data => { /* handle data or show error */ })And on the PHP side:
if ( empty($api_response) ) { wp_send_json( array('error' => 'no data') ); } wp_send_json( $api_response );If it helps, I put a tiny demo and the full snippet I used on a test page so you can inspect the network response and console behavior directly: https://suiigasbillonlinecheck.pk/
That demo shows both the bad response (empty) and the fixed behavior so you can compare. Hope that saves you some debugging time!
-
thank you so much daniel its very helpfull for me.now i understand the whats the main problem
-
Check if the API response is returning valid JSON — sometimes even a small HTML error breaks the fetch. Also make sure your PHP uses
wp_send_json()and not plainecho, that usually fixes blank results after submission.
- The topic ‘Tool not showing results after user submits form’ is closed to new replies.