📄 xmlhttprequest.js
字号:
var bAsync = ( typeof(asyncFunctionPointer) == 'function' ) ;
var oXmlHttp = this.GetHttpRequest() ;
oXmlHttp.open( "POST", urlToCall, bAsync ) ;
if ( bAsync ) {
oXmlHttp.onreadystatechange = function()
{
if ( oXmlHttp.readyState == 4 ) {
if ( oXmlHttp.status == 200 ) {
asyncFunctionPointer( oXmlHttp.responseXML ) ;
}
else {
alert( 'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')' ) ;
}
}
}
}
oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
oXmlHttp.send( data ) ;
if ( ! bAsync ) {
if ( oXmlHttp.status == 200 ) {
this.DOMDocument = oXmlHttp.responseXML ;
}
else {
alert( 'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')' ) ;
}
}
}
//--BBSXml with Object
BBSXml.prototype.GetUrlTextInObj = function( urlToCall, asyncFunctionPointer )
{
var oBBSXml = this ;
//var bAsync = ( typeof(asyncFunctionPointer) == 'function' ) ;
var bAsync = ( typeof(asyncFunctionPointer) == 'object' ) ;
var oXmlHttp = this.GetHttpRequest() ;
oXmlHttp.open( "GET", urlToCall, bAsync ) ;
if ( bAsync ) {
oXmlHttp.onreadystatechange = function()
{
if ( oXmlHttp.readyState == 4 ) {
if ( oXmlHttp.status == 200 ) {
//asyncFunctionPointer( oXmlHttp.responseText ) ;
asyncFunctionPointer.execute( oXmlHttp.responseText ) ;
}
else {
alert( 'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')' ) ;
}
}
}
}
oXmlHttp.send( null ) ;
if ( ! bAsync ) {
if ( oXmlHttp.status == 200 ) {
this.DOMDocument = oXmlHttp.responseXML ;
}
else {
alert( 'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')' ) ;
}
}
}
BBSXml.prototype.PostUrlTextInObj = function( urlToCall, data, asyncFunctionPointer )
{
var oBBSXml = this ;
//var bAsync = ( typeof(asyncFunctionPointer) == 'function' ) ;
var bAsync = ( typeof(asyncFunctionPointer) == 'object' ) ;
var oXmlHttp = this.GetHttpRequest() ;
oXmlHttp.open( "POST", urlToCall, bAsync ) ;
if ( bAsync ) {
oXmlHttp.onreadystatechange = function()
{
if ( oXmlHttp.readyState == 4 ) {
if ( oXmlHttp.status == 200 ) {
//asyncFunctionPointer( oXmlHttp.responseText ) ;
asyncFunctionPointer.execute( oXmlHttp.responseText ) ;
}
else {
alert( 'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')' ) ;
}
}
}
}
oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
oXmlHttp.send( data ) ;
if ( ! bAsync ) {
if ( oXmlHttp.status == 200 ) {
this.DOMDocument = oXmlHttp.responseXML ;
}
else {
alert( 'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')' ) ;
}
}
}
BBSXml.prototype.GetUrlXmlInObj = function( urlToCall, asyncFunctionPointer )
{
var oBBSXml = this ;
//var bAsync = ( typeof(asyncFunctionPointer) == 'function' ) ;
var bAsync = ( typeof(asyncFunctionPointer) == 'object' ) ;
var oXmlHttp = this.GetHttpRequest() ;
oXmlHttp.open( "GET", urlToCall, bAsync ) ;
if ( bAsync ) {
oXmlHttp.onreadystatechange = function()
{
if ( oXmlHttp.readyState == 4 ) {
if ( oXmlHttp.status == 200 ) {
//asyncFunctionPointer( oXmlHttp.responseXML ) ;
asyncFunctionPointer.execute( oXmlHttp.responseXML ) ;
}
else {
alert( 'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')' ) ;
}
}
}
}
oXmlHttp.send( null ) ;
if ( ! bAsync ) {
if ( oXmlHttp.status == 200 ) {
this.DOMDocument = oXmlHttp.responseXML ;
}
else {
alert( 'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')' ) ;
}
}
}
BBSXml.prototype.PostUrlXmlInObj = function( urlToCall, data, asyncFunctionPointer )
{
var oBBSXml = this ;
//var bAsync = ( typeof(asyncFunctionPointer) == 'function' ) ;
var bAsync = ( typeof(asyncFunctionPointer) == 'object' ) ;
var oXmlHttp = this.GetHttpRequest() ;
oXmlHttp.open( "POST", urlToCall, bAsync ) ;
if ( bAsync ) {
oXmlHttp.onreadystatechange = function()
{
if ( oXmlHttp.readyState == 4 ) {
if ( oXmlHttp.status == 200 ) {
asyncFunctionPointer.execute( oXmlHttp.responseXML ) ;
}
else {
alert( 'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')' ) ;
}
}
}
}
oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
oXmlHttp.send( data ) ;
if ( ! bAsync ) {
if ( oXmlHttp.status == 200 ) {
this.DOMDocument = oXmlHttp.responseXML ;
}
else {
alert( 'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')' ) ;
}
}
}
//--
function changeStyle(elementID,toStyle) {
document.getElementById(elementID).className=toStyle;
}
function getRadioValue(formName,radioName) {
var radios = eval("document."+formName+"."+radioName);
for (var i = 0; i < radios.length; i++) {
if (radios[i].checked) {
return radios[i].value;
}
}
}
function getRadioValueByName(radioName) {
var radioValues = document.getElementsByName(radioName);
for (var i = 0; i < radioValues.length; i++) {
if (radioValues[i].checked) {
return radioValues[i].value;
}
}
}
function getCheckBoxValue(checkBoxName) {
var checkBox = document.getElementById(checkBoxName);
if (checkBox.checked) {
return checkBox.value;
}
return "";
}
function getCheckBoxSingleValue(checkBoxId) {
var checkBoxs = document.getElementsByName(checkBoxId);
for (var i = 0; i < checkBoxs.length; i++) {
if (checkBoxs[i].checked) {
return checkBoxs[i].value;
}
}
return "";
}
var req;
function executeXhrOfPost(callback, url,data) {
req = new XMLHttpRequest();
if (req) {
req.onreadystatechange = callback;
req.open("POST", url, true);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.send(data);
}
}
function executeXhrOfGet(callback, url) {
req = new XMLHttpRequest();
if (req) {
req.onreadystatechange = callback;
req.open("GET", url, true);
req.send();
}
}
function getResponseXMLMsgs(responseXML) {
return responseXML.getElementsByTagName("messages")[0];
}
function getResponseXMLMsgsCodeid(responseXML) {
var messages = getResponseXMLMsgs(responseXML);
//alert(messages);
//alert(messages.childNodes[1].childNodes[0].nodeValue);
//alert("messages.childNodes[0].childNodes[0]:"+messages.childNodes[0].childNodes[0]);
var x = messages.childNodes;
for (i = 0; i < x.length; i++) {
if (x[i].nodeName == "codeid") {
return x[i].childNodes[0].nodeValue;
}
}
return "E000";
//return messages.childNodes[0].childNodes[0].nodeValue;
}
function getResponseXMLMsgsMessage(responseXML) {
var messages = getResponseXMLMsgs(responseXML);
//alert(messages);
var x = messages.childNodes;
for (i = 0; i < x.length; i++) {
if (x[i].nodeName == "message") {
return x[i].childNodes[0].nodeValue;
}
}
//return messages.childNodes[1].childNodes[0].nodeValue;
return "Error";
}
function getResponseXMLMsgsText(responseXML) {
var messages = getResponseXMLMsgs(responseXML);
//alert(messages);
var x = messages.childNodes;
for (i = 0; i < x.length; i++) {
if (x[i].nodeName == "text") {
return x[i].childNodes[0].nodeValue;
}
}
//return messages.childNodes[2].childNodes[0].nodeValue;
return "";
}
function hiddenElement(elementName) {
document.getElementById(elementName).style.display = "none";
}
function displayElement(elementName) {
document.getElementById(elementName).style.display = "block";
}
function filterString(txt) {
var re = /\+/;
return txt.replace(re,"%2B");
}
function getElementValue(elementName) {
return $(elementName).value;
}
function getElementFilterValue(elementName) {
return filterString($(elementName).value);
}
function handleEnter(field, event) {
var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
if (keyCode == 13) {
return false;
}
return true;
}
function startsWith(txt,tar) {
if (txt.indexOf(tar) == 0) {
return true;
}
else {
return false;
}
}
function endsWith(txt,tar) {
var num = txt.lastIndexOf(tar);
if ((num != -1) && (tar == txt.substring(num,txt.length))) {
return true;
}
else {
return false;
}
}
function getActionMappingName(action) {
var value = action;
var question = action.indexOf("?");
if (question >= 0) {
value = value.substring(0, question);
}
var slash = value.lastIndexOf("/");
var period = value.lastIndexOf(".");
if ((period >= 0) && (period > slash)) {
value = value.substring(0, period);
}
return startsWith(value,"/") ? value : ("/" + value);
}
function getActionMappingURL(action) {
var value = contextPath;
var servletMapping = servletMappingStr;
var queryString;
var question = action.indexOf("?");
if (question >= 0) {
queryString = action.substring(question);
}
var actionMapping = getActionMappingName(action);
if (startsWith(servletMapping,"*.")) {
value += actionMapping;
value += servletMapping.substring(1);
}
else if (endsWith(servletMapping,"/*")) {
value += servletMapping.substring(0, servletMapping.length - 2);
value += actionMapping;
}
else if (servletMapping == "/") {
value += actionMapping;
}
if (queryString != undefined) {
value += queryString;
}
return value;
}
function getExtName(fileName){
if(fileName.lastIndexOf(".")<0) return "";
return fileName.substring(fileName.lastIndexOf(".")+1,fileName.length).toLowerCase();
}
//-->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -