简单ajax代码。
<script type="text/javascript">
<!--
//将用户输入异步提交到服务器
function ajaxSubmit(){
//获取用户输入
var question=document.forms[0].question.value;
//创建XMLHttpRequest对象
var xmlhttp;
try{
xmlhttp=new XMLHttpRequest();
}catch(e){
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
//创建请求结果处理程序
xmlhttp.onreadystatechange=function(){
if (4==xmlhttp.readyState){
if (200==xmlhttp.status){
var data=xmlhttp.responseText;
document.getElementById("result").innerHTML=data;
}else{
alert("error");
}
}
}
//打开连接,true表示异步提交
xmlhttp.open("post", "/dict/servlet/dictAction", true);
//当方法为post时需要如下设置http头
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
//发送数据
xmlhttp.send("question="+question);
}
</script>
相关文档:
$.ajax({
type: "post",
url: loginUrl,
data: "username=" +uname + "&password=" +pwd,
async: ......
AJAX (异步 JavaScript 和 XML) 是个新产生的术语,专为描述JavaScript的两项强大性能.这两项性
能在多年来一直被网络开发者所忽略,直到最近Gmail, Google suggest和google Maps的横空出世才使人
们开始意识到其重要性.
这两项被忽视的性能是:
* 无需重新装载整个页面便能向服务器发送请求.
* 对XML文档的解析和处理.
......
Ajax技术已经得到很广泛的应用,在Web开发中其核心就在于异步通信和局部刷新,极大地改善了用户体验,尤其适合于高频度、低数据量的场景。在不使用Ajax的Web应用中,一个页面处理中只有一次请求,客户端处理完后一次性提交,这种一次请求和一次提交的处理可能比较耗时,从而造成客户等待,使用Ajax把这一次请求和一次提交分 ......
ajax提交表单
关键字: ajax
function ajaxSubmitForm(form, resultDivId) {
var elements = form.elements;// Enumeration the form elements
var element;   ......