首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

html页面前台怎么获取后台JSON数据

2012-09-25 
html页面前台如何获取后台JSON数据import.jsp页面写的后台:List t allselect()JSONArray json new JSO

html页面前台如何获取后台JSON数据
import.jsp页面写的后台:
List t = allselect();
JSONArray json = new JSONArray().fromObject(t);
PrintWriter outpw = response.getWriter();
String jsonto = json.toString();
outpw.write(jsonto);
out.flush();
out.close();

html前台给如何去后台json的值
function import_data(){
$.ajax(  
{  
url: "import.jsp",  
dataType : "json",  
type: "post",  
timeout: 5000,  
success: showresult,  
error: function() { alert("error"); }  
}  
)
}
  function showresult(jsonto) {  
  alert(jsonto);  
  }  
<input type="button" value="数据导入" onClick="import_data()">
这样写有什么问题 为什么没数据出来
“import_data”的值为 null、未定义或不是 Function 对象

[解决办法]

Java code
$(function() {        $("#btn").click(function() {            $.ajax({                url : "import.jsp",                dataType : "json",                type : "post",                timeout : 5000,                success : showresult,                error : function() {                    alert("error");                }            });        });    });    function showresult(jsonto) {        alert(jsonto);    }<input type="button" value="数据导入" id="btn"/> 

热点排行