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配置
这个应该没问题吧,有问题QQ 1019990976 注明 csdn ext.ajax.request servlet
运行效果: