0
如何让play 2.1控制器函数执行捕获的外部url并将json数据对象返回给javascript。从javascript调用play 2.1控制器函数返回json数据对象
- 首先InputStream不打开外部URL。出错说出没有协议
- 玩不喜欢JSONObject作为返回。
代码进行 -
的Javascript
$.ajax({
url: "/documents/getjsontext/" + talksUrl ,
type: 'GET',
data: "",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function(data){ do_this(data);},
error: function() {alert("Error in Ajax Call");}
});
基于路由/文件/ acontext /:jsonurl controllers.Class.acontext(jsonurl:字符串)
public static JSONObject acontext(String jsonurl) {
InputStream is = new URL(jsonurl).openStream();
try {
BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
String jsonText = readAll(rd);
JSONObject json = new JSONObject(jsonText);
return json;
} finally {
is.close();
}
}
什么是“玩2.1控制器功能”?你在谈论http://www.playframework.com/?也许你想要做一个Ajax请求:https://developer.mozilla.org/en-US/docs/AJAX/Getting_Started。 –
是播放框架2.1 – Seekhow