读书人

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

发布时间: 2012-09-25 09:55:58 作者: rapoo

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"/> 

读书人网 >Java Web开发

热点推荐