Objeto a JSON JavaScript
var person={"first_name":"Tony","last_name":"Hawk","age":31};
var personJSONString=JSON.stringify(person);
Grepper
var person={"first_name":"Tony","last_name":"Hawk","age":31};
var personJSONString=JSON.stringify(person);
var settings = {
"url": "https://api-gate2.movieglu.com/filmsNowShowing/?n=10",
"method": "GET",
"timeout": 0,
"headers": {
"api-version": "v200",
"Authorization": "Basic A1B2c3D4E5f6H7I8j911M12=",
"client": "ABCD",
"x-api-key": "IyrBUDT7CuTTc6LH45mI5aAoG8",
"device-datetime": "2020-06-18T12:07:57.296Z",
"territory": "UK",
},
};
$.ajax(settings).done(function (response) {
console.log(response);
});
$("#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.')
});
});