p_request, _val, _loading_img){
if(http_request.responseXML.documentElement){
//alert(decodeURIComponent(http_request.responseXML.documentElement.xml));
}else{
//alert(decodeURIComponent(http_request.responseText));
}
alert(_val);
funHide(_loading_img);
}
1、GET
var ajax = new AjaxDO();
ajax.setLoadingImg(_loading_img);
ajax.setOnReadyStateChange(processRequest, _val);
ajax.Open("GET", url, true); //异步模式,
程序继续执行
ajax.Send("");
ajax.Open("GET", url, false); //非异步模式,
程序等待
ajax.Send("");
var xml_doc = ajax.getResponseText("XML");
var text_doc = ajax.getResponseText("TEXT");
2、POST
var ajax = new AjaxDO();
ajax.setLoadingImg(_loading_img);
ajax.setOnReadyStateChange(processRequest, _val);
ajax.Open("POST", url, true); //异步模式,
程序继续执行
ajax.Send(data);
ajax.Open("POST", url, false); //非异步模式,
程序等待
ajax.Send(data);
var xml_doc = ajax.getResponseText("XML");
var text_doc = ajax.getResponseText("TEXT");
注,客户端发送带有中文或HTML脚本的信息时,发送的信息必须调用:encodeURIComponent函数,例如:
var data = encodeURIComponent($(''message'').value);
实际是调用了两次,Ajax类内部又调用一次。
服务端(Java版)需要做下转码:
String message = request.getParameter("message");
message = URLDecoder.decode(message, "UTF-8");
*/
注,客户端发送带有中文或HTML脚本的信息时,发送的信息必须调用:encodeURIComponent函数,例如:
var data = encodeURIComponent($(''message'').value);
实际是调用了两次,Ajax类内部又调用一次。
服务端(Java版)需要做下转码:
String message = request.getParameter("message");
message = URLDecoder.decode(message, "UTF-8");
2、Demo.html复制代码 代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/uploadfile/201307/13/16155923317.gif" src="/uploadfile/201307/13/0F155926496.gif" width="15" /></div>
<script type="text/javascript" language="javascript"><!--
function processRequest(http_request, _val, _loading_img){
alert(http_request.responseXML.documentElement.xml);
//alert(http_request.responseText);
funHide(_loading_img);
}
// --></script>
<script type="text/javascript" language="javascript"><!--
var url = "/uploadfile/201307/13/40155926861.gif" width=15>