jquery + ajax 在服務器端使用json格式怎麼傳送數據? 求具體代碼 還有在客戶端 怎麼解析。感謝 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 List<Map<String, String>> list = new ArrayList<Map<String, String>>(); int total = dpDirectoryService.getDpDirectoryCount(dpDirectory); list = dpDirectoryService.getDpDirectoryInfo(dpDirectory); PrintWriter write = response.getWriter(); JSONObject o = new JSONObject(); o.put("total", total); o.put("rows", list); write.write(o.toString()); write.flush(); write.close(); o.clear();服务端直接用response.getWriter();输出JSON串。客户端请求:$.ajax({ type: "get", url: url, async: false, success: function(msg){ alert(msg);//这里的msg就是JSON串了 } }); 服务器端你用什么语言,java你可以用fastjson直接解析一个对象,返回JSON字符串,然后用response对象输出他。php直接用echo json_encode(array('name'=>'吴红军'));这样输出返回给客户端jquery ajax这样获取:$.ajax({ url:'服务器端地址', type:'GET',//以GET方式请求, data:{id:1},//你需要传递的数据,我这里id:1随便写的 dataType:'json',//如果放回json,这里必须明确表示为json,否则他不理你的, success:function(rs){ rs.xxx//xxx就是你的数据,干你想干的事情都在这里。 }}); 服務器我用sturts2.0 進行數據推送 struts2你先要获取response对象,然后response 输出那个falstjson转换后的字符串就行了。具体可以加我:54963779 import net.sf.json.JSONObject; 這包已經加進來了啊! 如果是$.ajax({ url:'http://192.168.1.1/123.asp', type:'GET',//以GET方式请求, data:{id:1},//你需要传递的数据,我这里id:1随便写的 dataType:'json',//如果放回json,这里必须明确表示为json,否则他不理你的, success:function(rs){ rs.xxx//xxx就是你的数据,干你想干的事情都在这里。 }});那么123.asp的代码应乍个写? 如果是$.ajax({ url:'http://192.168.1.1/123.asp', type:'GET',//以GET方式请求, data:{id:1},//你需要传递的数据,我这里id:1随便写的 dataType:'json',//如果放回json,这里必须明确表示为json,否则他不理你的, success:function(rs){ rs.xxx//xxx就是你的数据,干你想干的事情都在这里。 }});那么123.asp的代码应乍个写? 在jsp网页中如何调用package中的类 求struts2的一个网站例子 请教一下,如何变换验证码的问题 问题:关于struts j2se api 文档哪里有DOWN! jsp利用MSChart控件在excel中生成统计图形 cookie.setPath("/") 是什么意思? 有什么作用?? 我有100多个点 怎样在B/S下按次序画图(曲线)?!并最后要闭合! 急!在java中怎么读取ini文件 这种效果是怎么实现的? input 默认值的问题 struts的s:iterator标签能获取到List的内容不能获取ArrayList的内容?麻烦大家过来看下 先谢谢了
List<Map<String, String>> list = new ArrayList<Map<String, String>>();
int total = dpDirectoryService.getDpDirectoryCount(dpDirectory);
list = dpDirectoryService.getDpDirectoryInfo(dpDirectory);
PrintWriter write = response.getWriter();
JSONObject o = new JSONObject();
o.put("total", total);
o.put("rows", list);
write.write(o.toString()); write.flush();
write.close();
o.clear();服务端直接用response.getWriter();输出JSON串。
客户端请求:
$.ajax({
type: "get",
url: url,
async: false,
success: function(msg){
alert(msg);//这里的msg就是JSON串了
}
});
输出他。
php直接用echo json_encode(array('name'=>'吴红军'));这样输出返回给客户端jquery ajax这样获取:$.ajax({
url:'服务器端地址',
type:'GET',//以GET方式请求,
data:{id:1},//你需要传递的数据,我这里id:1随便写的
dataType:'json',//如果放回json,这里必须明确表示为json,否则他不理你的,
success:function(rs){
rs.xxx//xxx就是你的数据,干你想干的事情都在这里。
}
});
具体可以加我:54963779
import net.sf.json.JSONObject;
這包已經加進來了啊!
$.ajax({
url:'http://192.168.1.1/123.asp',
type:'GET',//以GET方式请求,
data:{id:1},//你需要传递的数据,我这里id:1随便写的
dataType:'json',//如果放回json,这里必须明确表示为json,否则他不理你的,
success:function(rs){
rs.xxx//xxx就是你的数据,干你想干的事情都在这里。
}
});那么123.asp的代码应乍个写?
$.ajax({
url:'http://192.168.1.1/123.asp',
type:'GET',//以GET方式请求,
data:{id:1},//你需要传递的数据,我这里id:1随便写的
dataType:'json',//如果放回json,这里必须明确表示为json,否则他不理你的,
success:function(rs){
rs.xxx//xxx就是你的数据,干你想干的事情都在这里。
}
});那么123.asp的代码应乍个写?