Files
chrometophone/third_party/operatophone/send_logic.js
2010-12-13 12:27:02 +00:00

42 lines
1.2 KiB
JavaScript

/*
* Portions of this page are modifications based on work created and shared
* by Google and used according to terms described in the Creative Commons 3.0
* Attribution License.
*/
var channel;
var socket;
var req = new XMLHttpRequest();
function sendToPhone( data, listener ) {
req.open('POST', sendUrl, true);
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
req.setRequestHeader('X-Same-Domain', 'true'); // XSRF protector
req.onreadystatechange = function() {
if (this.readyState == 4) {
if (req.status == 200) {
var body = req.responseText;
if (body.indexOf('OK') == 0) {
listener(STATUS_SUCCESS);
} else if (body.indexOf('LOGIN_REQUIRED') == 0) {
listener(STATUS_LOGIN_REQUIRED);
} else if (body.indexOf('DEVICE_NOT_REGISTERED') == 0) {
listener(STATUS_DEVICE_NOT_REGISTERED);
}
} else {
listener(STATUS_GENERAL_ERROR);
}
}
};
var postData = '';
for(var key in data) {
if(postData.length > 1)
postData += '&';
if( data[key] !== null )
postData += key + '=' + encodeURIComponent( data[key] );
}
req.send(postData);
}