1
var xmlHttpRequest = null;
function ajaxSubmit()
{
if(window.ActiveXObject) //IE浏览器
{
xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest) //IE浏览器以外的其他浏览器
{
xmlHttpRequest = new XMLHttpRequest();
}
if(null != xmlHttpRequest)
{
var v = document.getElementById("value1");
xmlHttpRequest.open("GET", "AjaxServlet?v=" + v, true);
// 关联好ajax的回调函数
xmlHttpRequest.onreadystatechange = ajaxCallback;
//真正向服务器端发送数据
//使用Post方式提交,必须要加上下面一行,且是在send中发送数据,不是在open函数中
//xmlHttpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttpRequest.send(null);
}
}
function ajaxCallback()
{
if(xmlHttpRequest.readyState == 4)
{
if(xmlHttpRequest.status == 200)
{
var responseText = xmlHttpRequest.responseText;
document.getElementById("div1").innerHTML = responseText;
}
}
}
2
<html> $(document).ready(function () //$.post()方式: //$.get()方式: function update_page (json) //回传函数实体,参数为XMLhttpRequest.responseText <div id="result" style="background:orange;border:1px solid red;width:300px;height:200px;"></div> </body>
<?php function my_json_encode($phparr) |