1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
| function sendAjax() { if (sync == false) return ;
var name = document.getElementById("name").value; var info = document.getElementById("info").value;
if (name == "") return ; var XHR = null; var FD = new FormData(); var noblank_name = name.replace(/(^\s*)|(\s*$)/g,""); if (noblank_name != name){ name = noblank_name; document.getElementById("name").value = name; } if (window.XMLHttpRequest) { XHR = new XMLHttpRequest(); } else if (window.ActiveXObject) { XHR = new ActiveXObject("Microsoft.XMLHTTP"); } FD.append("name", name); FD.append("info", info); FD.append("info2", sync_last_text); XHR.onreadystatechange = function () { if (XHR.readyState == 4 && XHR.status == 200) { if (sync == false) return ; var new_info = XHR.responseText; new_info = decodeURI((encodeURI(new_info)).replace(/%0D/g, ""));
if (new_info == ""); else if (document.getElementById("name").value != name); else if (info == new_info); else if (document.getElementById("info").value == new_info); else if (sync_last_text == new_info); else if ((new Date()).getTime() <= save_time + 3000); else if (save_text == new_info); else { var myDate = new Date();
if (sync_auto == true && document.getElementById("info").value == save_text ) { document.getElementById("info").value = new_info; save_text = new_info;
mdui.snackbar({ message: '已更新 '+myDate.getHours()+":"+myDate.getMinutes()+":"+myDate.getSeconds(), buttonText: '撤销并关闭自动修改', onButtonClick: function() { document.getElementById("info").value = info; save_text = info; sync_auto = false; }, }); } else { mdui.snackbar({ message: '收到更新'+myDate.getHours()+":"+myDate.getMinutes()+":"+myDate.getSeconds(), buttonText: '修改', onButtonClick: function() { document.getElementById("info").value = new_info; save_text = new_info; }, }); } }
sync_last_text = new_info;
sendAjax(); } } XHR.open('POST', 'sync_ajax.php', true); XHR.send(FD); return false; }
|