当前位置: 代码迷 >> Java Web开发 >> html页面前台怎么获取后台JSON数据
  详细解决方案

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

热度:8540   发布时间:2013-02-25 21:11:27.0
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"/>
  相关解决方案