express/public/javascripts/mail.js
// This function sends the request to the server
This function sends the request to the server
This function sends the request to the server
function ajaxPostMail(form, callback) {
	var url = form.querySelector('.action').value,
		xhr = new XMLHttpRequest(),
		params = [];
	for (var i = 0, name, value; i < form.elements.length; i++) {
		name = encodeURIComponent(form.elements[i].name);
		value = encodeURIComponent(form.elements[i].value);
		params.push(name + '=' + value);
	}
	params.push(encodeURIComponent('ajax') + "=" + encodeURIComponent(true)); 
	params = params.join('&');
	xhr.onreadystatechange = function() {
		if (xhr.readyState === 4) {
			if (xhr.status === 200) {
				callback(JSON.parse(xhr.responseText));
			} else {
				callback(['failure']);
			}
		}
	};
	xhr.open('POST', url, true);
	xhr.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	xhr.send(params);
}
function ajaxPostMail ( form , callback ) { var url = form . querySelector ( '.action' ) . value , xhr = new XMLHttpRequest ( ) , params = [ ] ; for ( var i = 0 , name , value ; i < form . elements . length ; i ++ ) { name = encodeURIComponent ( form . elements [ i ] . name ) ; value = encodeURIComponent ( form . elements [ i ] . value ) ; params . push ( name + '=' + value ) ; } params . push ( encodeURIComponent ( 'ajax' ) + "=" + encodeURIComponent ( true ) ) ; params = params . join ( '&' ) ; xhr . onreadystatechange = function ( ) { if ( xhr . readyState === 4 ) { if ( xhr . status === 200 ) { callback ( JSON . parse ( xhr . responseText ) ) ; } else { callback ( [ 'failure' ] ) ; } } } ; xhr . open ( 'POST' , url , true ) ; xhr . setRequestHeader ( 'Content-type' , 'application/x-www-form-urlencoded' ) ; xhr . send ( params ) ; }
This function sends the request to the server
This function sends the request to the server
// Building up the request... // This is sent with ajax // Recording the response // Opening the connection //All preparations are clear, send the request!