1var person={"first_name":"Tony","last_name":"Hawk","age":31};
2var personJSONString=JSON.stringify(person);
1$("#ajaxForm").submit(function(e){
2 e.preventDefault();
3 var action = $(this).attr("action");
4 var data = {};
5 $(this).serializeArray().map(function(x){data[x.name] = x.value;});
6 $.ajax({
7 type: "POST",
8 url: action,
9 data: JSON.stringify(data),
10 contentType: "application/json",
11 headers: {
12 "Accept": "application/json"
13 }
14 }).done(function() {
15 $('.success').addClass('is-active');
16 }).fail(function() {
17 alert('An error occurred please try again later.')
18 });
19});