Answers for "post() javascript"

1

javascript send post

var xhr = new XMLHttpRequest();
xhr.open("POST", yourUrl, true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({
    value: value
}));
Posted by: Guest on December-27-2020
2

post method javascript code

const postData = async ( url = '', data = {})=>{
    console.log(data);
      const response = await fetch(url, {
      method: 'POST', 
      credentials: 'same-origin',
      headers: {
          'Content-Type': 'application/json',
      },
     // Body data type must match "Content-Type" header        
      body: JSON.stringify(data), 
    });

      try {
        const newData = await response.json();
        console.log(newData);
        return newData;
      }catch(error) {
      console.log("error", error);
      }
  }
Posted by: Guest on May-10-2020
1

jquery $.post

// Assign handlers immediately after making the request,
// and remember the jqxhr object for this request
var jqxhr = $.post( "example.php", function() {
  alert( "success" );
})
  .done(function() {
    alert( "second success" );
  })
  .fail(function() {
    alert( "error" );
  })
  .always(function() {
    alert( "finished" );
  });
 
// Perform other work here ...
 
// Set another completion function for the request above
jqxhr.always(function() {
  alert( "second finished" );
});
Posted by: Guest on May-21-2020
1

$.post javascript

//$.post with jQuery

$.post(
  "path/to/your/php/file", 
  {
    param1: "Value",
    param2: "Value"
},
  function(data) {
  //Callback here
  }
);
Posted by: Guest on July-21-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language