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 对象

解决方案 »

  1.   

    ajax 请求url为Action,Atcion再跳转到import.jsp。
      

  2.   


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

  3.   

    找找js解析json的例子,你的回调函数jsonto就是一个json数组
    直接在回调函数里面解析json,然后用js控制让它在什么地方显示