最高半折刷qq各种业务和钻(家里人自己开的,尽管放心,大家多捧捧场)

sking7

导航

JSONP, 简单应用。。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Top Customers with Callback</title>
</head>
<body>
<div id="divCustomers">hello</div>
<script type="text/javascript">
var a;
function onCustomerLoaded(result,arr)
{
//console.log('-------');
alert(result.name);//测试对象和数组..
for(i in arr){
alert(arr[i]);
}
}
</script>
<script type="text/javascript" src="http://localhost:8080/SendJsonP/servlet/responseJson?callBack=onCustomerLoaded"></script>

</body>
</html>

请求另外域名中的一个servlet。。

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String funName=request.getParameter("callBack");//得到需要调用的函数名
PrintWriter out = response.getWriter();
out.write(funName+"({name:'sking7'},['a','b'])");//返回参数对象,和数组
out.flush();
out.close();
}



posted on 2011-11-10 23:16  G.N&K  阅读(146)  评论(0编辑  收藏  举报