I wrote some code using javascript to submit checkbox form data to PHP. But the php cannot get the data. The following are my codes. Thanks in advance.
HTML CODE:
<form onchange="fetch()" method="post">
<input type="checkbox" name="formname[]" value="value1" />
<input type="checkbox" name="formname[]" value="value2" />
</form>
Javascript Code:
<script>
function fetch() {
var data = new FormData();
data.append("formname[]", document.getElementsByName("formname[]"));
var xhr = new XMLHttpRequest();
xhr.open("POST", "the url to php code", true);
xhr.send(data);
...
</script>
PHP Code:
$result = $_POST['formname']