Answers for "ajax convert to js"

41

object to json javascript

var person={"first_name":"Tony","last_name":"Hawk","age":31};
var personJSONString=JSON.stringify(person);
Posted by: Guest on July-23-2019
0

ajax convert to js

$("#ajaxForm").submit(function(e){
  e.preventDefault();
  var action = $(this).attr("action");
  var data = {};
  $(this).serializeArray().map(function(x){data[x.name] = x.value;}); 
  $.ajax({
    type: "POST",
    url: action,
    data: JSON.stringify(data),
    contentType: "application/json",
    headers: {
      "Accept": "application/json"
    }
  }).done(function() {
     $('.success').addClass('is-active');
  }).fail(function() {
     alert('An error occurred please try again later.')
  });
});
Posted by: Guest on August-04-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language