Send Json data via XMLHttpRequest - Javascript Language Basics

Javascript examples for Language Basics:XMLHttpRequest

Description

Send Json data via XMLHttpRequest

Demo Code

ResultView the demo in separate window

<html>
   <head>
      <title>Web Page Design</title> 
      <script>
function sayHello() {/*  ww  w. j a  v a  2s .  c  om*/
 var  xhr = new XMLHttpRequest();
 var url = "http://localhost:5043";
 xhr.open("POST", url, true);
 xhr.setRequestHeader("Content-type", "application/json");
 var data = JSON.stringify({"test" : "hello"});
 xhr.send(data);
}
sayHello();

      </script> 
   </head>
   <body>  
   </body>
</html>

Related Tutorials