Mixed Content Blocked When Running an HTTP AJAX Operation in an HTTPS Page
You are likely running into a hard stop enforced by modern browsers: mixed content errors. This occurs when your application is served over HTTPS, but it attempts to fetch resources or submit data via a protocol that is not secure. The browser treats this as a potential security vulnerability because an attacker on the same network could potentially intercept or modify the request if they can control the HTTP endpoint.
In your specific scenario, you are submitting a form to ViciDial via http://XX.XXX.XX.XX, while your main page resides at https://page.com. When you switch to an AJAX request, the browser blocks the XMLHttpRequest because it detects the protocol mismatch immediately. Simply changing the URL in your code to https:// won't work if the target server (ViciDial) is actually listening on port 80 and not port 443. The error message explicitly states that the content must be served over HTTPS, but you are constrained by the legacy nature of the CRM endpoint.
The core conflict here is architectural. You want to use AJAX to handle the data submission without a full page reload, which provides a smoother user experience. However, mixed content blocks this behavior entirely to prevent security risks. The browser does not allow an insecure sub-resource to be loaded within a secure context. This means you cannot simply "fix" it from the client-side JavaScript alone if the target API remains HTTP.
To resolve this while maintaining the desired flowâsubmitting data and landing on a thank-you pageâyou need to shift the logic from the browser to the server. Since the client is already trusted (HTTPS), the server can act as a secure proxy for the insecure request.
Create an intermediate PHP file on your own HTTPS domain. This file will intercept the form submission, extract the necessary data, and forward it to the ViciDial API using curl. Because this forwarding happens entirely within the server environment, the browser never sees the direct connection to the HTTP endpoint, thereby bypassing the mixed content restriction.
Here is a conceptual example of how that server-side script might look:
<?php
// Secure HTTPS Endpoint on your domain
header('Content-Type: text/html');
// Read and sanitize input data from the form
$input = $_GET['queries'] ?? ''; // Ensure you handle sanitization based on actual form fields
if (!empty($input)) {
// Forward to ViciDial via CURL (Server-side call)
$url = "http://XX.XXX.XX.XX/vicidial/non_agent_api.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// If the API requires POST or specific headers, configure them here
// Execute the request
$response = curl_exec($ch);
curl_close($ch);
if ($response === false) {
http_response_code(500);
echo "Error processing request.";
} else {
// If successful, redirect to your thank-you page
header("Location: https://www.example.com/thank-you");
exit;
}
} else {
http_response_code(400);
echo "Missing form data.";
}
?>
Your AJAX script can now point to this new HTTPS endpoint instead of the raw ViciDial API. The browser sends the data securely to your domain, your PHP script handles the insecure outbound request internally, and then redirects the user to the final destination.
This approach preserves the single-page application feel without violating security policies. It also isolates the legacy HTTP dependency behind a secure wall. Just ensure that your intermediate script validates input rigorously before forwarding it, as you are effectively acting as a bridge between two different trust levels.
