0

I want to send 'GET' and 'POST' requests using ajax in Django. I looked few articles but they all were using jquery, I don't know how to use jquery so is there any way I can send 'GET' and 'POST' requests by using plain JavaScript.

Ankit Kumar
  • 389
  • 3
  • 9
  • Possible duplicate of https://stackoverflow.com/questions/6396101/pure-javascript-send-post-data-without-a-form – Nick ODell Sep 27 '21 at 02:42

1 Answers1

0

You can use XMLHttpRequest Object of vanilla JS

For Get Request

var xhttp = new XMLHttpRequest();
xhttp.open("GET", "ajaxfile.php?request=1", true);
xhttp.send();

For Post Request

var xhttp = new XMLHttpRequest();
xhttp.open("POST", "ajaxfile.php", true); 
var PostData = {name:'yogesh',salary: 35000,email: 'yogesh@makitweb.com'};
xhttp.send(JSON.stringify(postData));