HTML/JS code snippet is failing with error… Failed to load r

Problems with the Windows version of XAMPP, questions, comments, and anything related.

HTML/JS code snippet is failing with error… Failed to load r

Postby nageshc » 05. July 2023 19:03

HTML/JS code snippet is failing with error… Failed to load resource: the server responded with a status of 405 (Method Not Allowed)

I checked all the php related entries in httpd.conf
LoadModule php_module
AddType application/x-httpd-php .php
checked for latest version of php.


// Send a POST request to the PHP file
var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://localhost:8080/saveXML.php', true);

// Set the Content-Type header to indicate form data
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

// Convert the form data to a query string
var queryString = new URLSearchParams(formData).toString();

// Send the query string
xhr.send(queryString);

// Handle the response or perform any additional actions
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
console.log('XML file saved successfully');
} else {
console.log('XML file save FAILED');
}
}
};

Php code.
<?php
//header('Allow: POST');
//error_reporting(E_ALL);
//ini_set('log_errors', 1);
//ini_set('error_log', 'php_errors.log');
header("Access-Control-Allow-Origin: http://localhost:8080");
header("Access-Control-Allow-Methods: POST, GET, OPTIONS"); // Include the HTTP methods you intend to allow
header("Access-Control-Allow-Headers: Content-Type"); // Include the headers you intend to allow

log_errors = On
error_reporting = E_ALL


// Get the value from the HTML input field
$memberIdValue = $_POST['memberId'];
$fnameValue = $_POST['fname'];
…… other lines to populate the data received.

// Define the key value to search for in the XML file
$memberId = $memberIdValue;

// Load the XML file
$xmlFile = 'familyTree.xml';
$xml = simplexml_load_file($xmlFile);

// Find the person element with the specified memberId
$person = $xml->xpath('//person[memberId="' . $memberId . '"]');
if (!empty($person)) {
$person[0]->fname = $fnameValue;
$person[0]->lname = $lnameValue;
… other lines

// Save the modified XML back to the file
$xml->asXML($xmlFile);

echo 'XML file updated successfully.';
} else {
echo 'Person with memberId ' . $memberId . ' not found in the XML file.';
}
?>
nageshc
 
Posts: 2
Joined: 05. July 2023 18:50
XAMPP version: 3.3.0
Operating System: Windows 11

Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 170 guests