Sindbad~EG File Manager

Current Path : /home/beeson/public_html/WebMathXpert/
Upload File :
Current File : //home/beeson/public_html/WebMathXpert/FetchMessage.js

// Function to send message to the Engine
function sendMessageToEngine(message, param) {
    // Create the data object to be sent
	const data = {
		message: message,
		param: param
	};
	console.log("in sendMessageToEngine with ", param,data);
   let baseURL = window.location.hostname === 'localhost' ? "https://localhost:8443" : "https://mathxpert.org";
	const target = `${baseURL}/EnginePortal.php`;
	console.log(target);
	return fetch(target, { 
		method: 'POST',  
		mode: "cors", // Enforce CORS mode, preventing "access denied" 
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded',
		},
		body: new URLSearchParams(data), // Send data as key-value pairs
		credentials: 'include'  // 🔥 This ensures cookies (session) are sent!  Added 2.21.25
	})
	.then(response => response.text()) // Parse the response
	.then(result => {
		console.log("got back to FetchMessage with answer");
		//  console.log(result);
		return result;
	})
	.catch(error => {
		console.error('Error communicating with Engine:', error, message);
	});
}

// note 3.11.25,  cors and credentials were necessary to make repeated use
// of the arrowButton possible on the remote server.  I don't know why, as
// you can initially use the arrowButton, but after several uses it fails
// if cors and credentials are not in the code here.  When they are missing,
// only the arrowButton stops--the Engine is still working. 

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists