79789626

Date: 2025-10-13 20:51:45
Score: 0.5
Natty:
Report link

When you specify a Content-Type of application/x-www-form-urlencoded, the XMLHttpRequest API is expecting that your post data be formatted just like query parameters. i.e.: ip=val1&ua=val2&country=val3. The following code should post to your script by first encoding the FormData entries into a URLSearchParams instance, then exporting that to a string.

var data = new FormData();
data.append('ip', 'val');
data.append('ua', 'val2');
data.append('country', 'val3');

var xhr = new XMLHttpRequest();
xhr.open('POST', 'visitor.php?type=visitorControl', true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
var params = new URLSearchParams(data);
xhr.send(params.toString());
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Starts with a question (0.5): When you
  • Low reputation (1):
Posted by: William Merfalen