Quantcast
Channel: WampServer - WampServer English
Viewing all articles
Browse latest Browse all 3177

wamp 3.1.7 does not handle "Content-Type", "application/json" (no replies)

$
0
0
wamp server does not handle xhr.setRequestHeader("Content-Type", "application/json") when using POST!
what is wrong? i already tried to config apache... no success.

i now have a html file:

<!DOCTYPE html>
<html>
<body>

<input id="clickMe" type="button" value="clickme" onclick="serverTestPost('bert');" />

<script>


function serverTestPost(strTest){

console.log("serverTestFunction");


xhr = new XMLHttpRequest();
//xhr.open("POST", departureReceiverAddress, true);
xhr.open("POST", "postTestReceiver.php", true);
//xhr.setRequestHeader("Content-Type", "application/json");
//xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
var json = JSON.parse(xhr.responseText);
console.log(json.email + ", " + json.name)
}
}
//xhr.send(data);
//xhr.send("foo=bar&lorem=ipsum");
var data = JSON.stringify({"email":"tomb@raider.com","name":"LaraCroft"});
xhr.send(data);
}
</script>

</body>
</html>

and a php

<html>
<body>

Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>

</body>
</html>

Viewing all articles
Browse latest Browse all 3177

Trending Articles