java ajax报错500,(Struts2+JSON+Ajax) XMLHttpRequest ==500如何解决
(Struts2+JSON+Ajax) XMLHttpRequest ==500怎么解決?
本帖最后由 zjlisok 于 2013-01-29 02:00:05 編輯
XMLHttpRequest.status==500奇怪了,搞了半天還沒有解決。
朋友們請幫我一把,謝謝!
廢話不說,先上代碼
JS代碼:
var?xmlhttp;
//ajax方法
function?createXMLHttpRequest(){
if(window.ActionXObject){
xmlhttp=new?ActionXObject("Microsoft.XMLHTTP");
}else?if(window.XMLHttpRequest){
xmlhttp=new?XMLHttpRequest();
}
alert("ajax啟動");
}
//showList()
function?showList(){
createXMLHttpRequest();
xmlhttp.open("GET","getList.action?date="+new?Date().getTime(),true);
xmlhttp.onreadystatechange?=?returnListString;
xmlhttp.send();
alert("showList啟動");
}
//從action取回數據
function?returnListString(){
if(xmlhttp.readyState==4){
alert("xmlhttp.readyState==4");
alert("xmlhttp.status"+xmlhttp.status);
if(xmlhttp.status==200){
var?returnJsonString?=?xmlhttp.responseText;
var?jsonString=JSON.parse(returnJsonString);
var?showString="";
for(var?i=0;i
showString+=jsonString[i]+"\n";
}
alert(showString);
$("#show").html(showString);
}
}
}
Action:
public?class?UrlString?extends?ActionSupport?{
public?void??listString()?throws?IOException{
List?list?=?new?ArrayList();
list.add("zjl");
list.add("123");
JSONArray?jsonArray?=?JSONArray.fromObject(list);
System.out.println("jsonArray="+jsonArray.toString());
ServletActionContext.getResponse().setContentType("text/html");
ServletActionContext.getResponse().setCharacterEncoding("utf-8");
ServletActionContext.getResponse().getWriter().printf(jsonArray.toString());
ServletActionContext.getResponse().getWriter().flush();
ServletActionContext.getResponse().getWriter().close();
}
}
status.xml:
xmlhttprequest
struts
ajax
json
action
------解決方案--------------------
服務器代碼錯誤。
最好發一下服務器端的報錯原因。。
你這是把action當servlet用是么?
------解決方案--------------------
先把服務器端報的異常貼出來看看
------解決方案--------------------
引用:引用:服務器代碼錯誤。
最好發一下服務器端的報錯原因。。
你這是把action當servlet用是么?
完全沒有異常,就是XMLHttpRequest.status==500
500服務器內部錯誤,你是不是把異常給拋出了?
你把你的控制臺截個圖我看看。。
------解決方案--------------------
500錯誤是后臺出錯??我也遇見過??你進行調試就可看得到??哪里出錯了
------解決方案--------------------
總結
以上是生活随笔為你收集整理的java ajax报错500,(Struts2+JSON+Ajax) XMLHttpRequest ==500如何解决的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: html跳转网页为什么网页无法访问,朋友
- 下一篇: hadoop 运行java类_hadoo