Ajax异步刷新
注意:
1、<div id="iframe">显示刷新的内容</div>
2、调用异步刷新:javascript:OnLink('地址')
<!--ajax异步刷新-->
<script type="text/javascript">
//创建XMLHttpRequestc对象
var xmlHttp=false;
//判断浏览器
function createXMLHttpRequest(){
if(window.ActiveXObject){//IE浏览器
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){}
}
}else{//其他浏览器:如mozilla 的 fireFox(火狐) 或者 netscape 7
xmlHttp=new XMLHttpRequest();
}
}
//提交获得值后的方法
function OnShow(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
var info=xmlHttp.responseText;
document.getElementById("iframe").innerHTML=info;
}
}
}
//要调用的方法
function OnLink(URL){
createXMLHttpRequest();
xmlHttp.open("post",URL,true);
xmlHttp.onreadystatechange=OnShow;
xmlHttp.send(null);
}
</script>
相关文档:
使用原始的XMLHttpRequest发出请求时,只能对Servlet和JSP操作
在JSP中创建3个function
1.createXmlHttpRequest----负责判断浏览器类型创建 XMLHttpRequest对象
var xmlHttpRequest;
function createXMLHttpRequest(){
// IE 浏览器
if(window.ActiveXObject){
&nbs ......
ScriptManager.RegisterStartupScript(p1, this.GetType(), "click", "alert('ok')", true);//p1是updatepanel的id
ScriptManager.RegisterStartupScript(p1, this.GetType(), "click", "alert('ok')", true);//p1是updatepanel的id
......
struts2版本:struts-2.1.8.1
异常:java.lang.NoClassDefFoundError: com/opensymphony/xwork2/util/TextUtils
原因:jsonplugin-0.34.jar 配合 struts2-core-2.1.8.1.jar 使用的情况下报的异常,但以前的项目中jsonplugin-0.34.jar 配合 struts2-core-2.1.6.jar 使用不会出现这样的异常
解决方法:去掉jsonplugin-0.34 ......
摘自:http://www.ibm.com/developerworks/library/wa-aj-jsonp1/
AJAX Same-Origin Policy(SOP) limitation:
AJAX prevents cross-domail invokation, there are several ways to by pass this limitation.
1. write a proxy on the server side. The SOP limitation only exists only on the javascript si ......