I've successfully used XMLHttpRequest in the past with the GET method, but I'm currently facing challenges trying to implement it using POST.
Here's the code snippet:
var req = null;
if (window.XMLHttpRequest)
{// for modern browsers like IE7+, Firefox, Chrome, Opera, Safari
req = new XMLHttpRequest();
}
else
{// for old versions like IE6, IE5
req = new ActiveXObject("Microsoft.XMLHTTP");
}
var url = "http://www.example.com/api.php";
var params = "data=someData";
req.open("POST", url, true);
req.send(params);
This code essentially triggers a PHP script which then inserts data into a database.