自定义的JS部分
/**
define js code by sheng
*/
function axSendMessage() {
var url = "testAjax";
var param = "name="+ $F("name");
var ajax = new Ajax.Request(url, {
method:"post",
parameters:param,
onComplete:callBack,
asynchronous:true
});
}
function callBack(content) {
var nameTip = $("nameTip");
for(var j = 0; j < nameTip.childNodes.length; j++) {
nameTip.removeChild(nameTip.childNodes.item(j));
}
var c = content.responseText;
var list = c.split("~~");
for(var i = 0; i < list.length; i++) {
var tempDiv = document.createElement("div");
tempDiv.innerHTML = list[i];
nameTip.appendChild(tempDiv);
}
}
new Form.Element.Observer("name", 1, axSendMessage);
本文介绍了一种自定义JavaScript代码实现Ajax请求的方法。通过编写特定的函数,如发送Ajax请求(`axSendMessage`)及处理响应内容(`callBack`),实现了与服务器端的数据交互。文章详细展示了如何创建Ajax实例、设置请求参数、指定回调函数等关键步骤。
171

被折叠的 条评论
为什么被折叠?



