webbrowner 监控 ajax,小权ajax.js

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

/**

* Ajax.js

*

* Collection of Scripts to allow in page communication from browser to (struts) server

* ie can reload part instead of full page

*

* How to use

* ==========

* 1) Call retrieveURL from the relevant event on the HTML page (e.g. onclick)

* 2) Pass the url to contact (e.g. Struts Action) and the name of the HTML form to post

* 3) When the server responds ...

* - the script loops through the response , looking for newContent

*  - each  tag in the *existing* document will be replaced with newContent

*

* NOTE:  is case sensitive. Name *must* follow the first quote mark and end in a quote

* Everything after the first '>' mark until  is considered content.

* Empty Sections should be in the format 

*/

//global variables

var req;

var which;

/**

* Get the contents of the URL via an Ajax call

* url - to get content from (e.g. /struts-ajax/sampleajax.do?ask=COMMAND_NAME_1)

* nodeToOverWrite - when callback is made

* nameOfFormToPost - which form values will be posted up to the server as part

*of the request (can be null)

*/

function retrieveURL(url,nameOfFormToPost) {

//get the (form based) params to push up as part of the get request

url=url+getFormAsString(nameOfFormToPost);

//Do the Ajax call

if (window.XMLHttpRequest) { // Non-IE browsers

req = new XMLHttpRequest();

req.onreadystatechange = processStateChange;

try {

req.open("GET", url, true); //was get

} catch (e) {

alert("Problem Communicating with Server\n"+e);

}

req.send(null);

} else if (window.ActiveXObject) { // IE

req = new ActiveXObject("Microsoft.XMLHTTP");

if (req) {

req.onreadystatechange = processStateChange;

req.open("GET", url, true);

req.send();

}

}

}

/*

* Set as the callback method for when XmlHttpRequest State Changes

* used by retrieveUrl

*/

function processStateChange() {

if (req.readyState == 4) { // Complete

if (req.status == 200) { // OK response

///alert("Ajax response:"+req.responseText);

//Split the text response into Span elements

spanElements = splitTextIntoSpan(req.responseText);

//Use these span elements to update the page

replaceExistingWithNewHtml(spanElements);

} else {

alert("Problem with server response:\n " + req.statusText);

}

}

}

/**

* gets the contents of the form as a URL encoded String

* suitable for appending to a url

* @param formName to encode

* @return string with encoded form values , beings with &

*/

function getFormAsString(formName){

//Setup the return String

returnString ="";

//Get the form values

formElements=document.forms[formName].elements;

//loop through the array , building up the url

//in the form /strutsaction.do&name=value

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值