1.js代码
Ext.onReady(function(){
Ext.Ajax.request({
url:"AjaxServlet.do?name=里杂谈",
//url:"AjaxServlet.do",
method:"get",
//params:{name:"xxx"},
success:function(res,config){
alert(config.url);
alert(config.method);
alert(res.responseText);
//var json = res.responseText;
var json = Ext.util.JSON.decode(res.responseText);
alert("xx");
Ext.MessageBox.alert("提示",json.author);
},
failure:function(){
Ext.MessageBox.alert("result","请求失败")
}
});
})
2.servlet
System.out.println("+++++");
response.setContentType("text/html,charset=utf-8");
PrintWriter out = response.getWriter();
String name1 = request.getParameter("name");
String name = "'"+name1+"'";
System.out.println(name);
Date date = new Date();
//String time = date.toString();
//String json = "{authon:" + name + ",time:" + time + "}";
String json = "{author:"+name+"}";//转换成json。格式{name:"name"},而不是{name:name}
out.println(json);
System.out.println(json);
out.flush();
out.close();
web.xml配置
标签:name,Ext,request,json,alert,String,ext,ajax,out From: https://blog.51cto.com/iwtxokhtd/6249331