jsonp的简单用法

 
test.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>test.html</title>
	
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
<script type="text/javascript" src="/jquery-latest.pack.js"></script>

<script type="text/javascript">
$.getJSON("http://www.web.com/test.jsp?callback=?",             //调用JSONP
function(json){ 
alert(json[0].name);
});
</script>
  </head>
  
  <body>
    This is my HTML page. <br>
  </body>
</html>

 test.jsp

 

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%String callback=request.getParameter("callback"); %>
<%	out.print(callback+"([ { name:\"John\"} ] )");%>

 

 

你可能感兴趣的:(JavaScript,jsonp,jquery,json,jsp)