var request = new XMLHttpRequest();
request.addEventListener('readystatechange', function (data) {
if (this.readyState == 4 && this.status >= 200 && this.status < 400) {
//data.responseText || data.responseXML;
}
});
request.open('POST', '...');
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
request.send(...);<form action="/engine/ajax/my_votepost.php" method="POST" id="votepost">...</form>$(document).on('submit', '#votepost', function (e) {
var form = $(this);
e.preventDefault();
$.ajax({
type: this.method,
url: this.action,
data: form.serialize()
}).done(function (result) {
form.html(result);
});
}); $(document).on('submit', '#testForm', function (e) {
if (!confirm('Вы действительно хотите отправить форму?')) {
e.preventDefault();
}
});<input type="button" id="twoSend" value="Send2">$(document).on('click', '#twoSend', function (e) {
if (confirm('Вы действительно хотите отправить форму?')) {
this.form.submit();
}
}); .frame:before,
.frame:after {
content: "";
display: table;
} var x = {
y: 0.020,
z: 0.12345
};
console.log(JSON.stringify(x, function(key, value) {
return typeof value == 'number' ? value.toFixed(3) : value;
})); // "{"y":"0.020","z":"0.123"}"console.log(JSON.stringify(x, function(key, value) {
return typeof value == 'number' ? Number(value.toFixed(3)) : value;
})); // "{"y":0.02,"z":0.123}" function updateInfo () {
$.ajax({
type: 'post',
url: '...',
data: '...',
dataType: 'json'
}).done(function (data) {
send();
function send () {
var row = data.splice(0, 1);
if (row.length) {
$.ajax({
type: 'post',
url: '...',
data: row[0]
}).done(send);
} else {
console.log('Done');
}
}
});
} <a href="#hidden_form" class="button btn_red popup_c" data-action="modal">text</a>$(document).on('click', 'a[href^="#"]', function (e) {
e.preventDefault();
switch ($(this).data('action')) {
case 'modal':
// Что-то для всплывашек
break;
case 'help':
// Напрмиер, для помощи
break;
default:
$('html, body').animate({
scrollTop: $('#' + this.hash.slice(1)).offset().top
}, 1000);
break;
}
});