Jump to content

How to send data in request body


Nati323

Recommended Posts

Hey all,

I want to send data to server using AJAX

But I dont want to send it via post/get variables

I want to send the data in the request body

in JQuery I just do:

 

 

$.ajax({
     url: 'someurl',
     data: 'foo'
});

 

But how can I do it in Pure JS ?

Link to comment
Share on other sites

You can just send data without any name/value pairs, any data you send will go in the request body. It will only get automatically parsed by something like PHP if it's in the name/value pair format.

 

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = ajax_handler;
xhttp.open("POST", "script.php", true);
xhttp.send('request body here');
You may still want to URL-encode the request body. In PHP, for example, you would get the request body by reading from the php input stream.

 

http://php.net/manual/en/wrappers.php.php

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...