【问题标题】:Value is not showing into alert box from Servlet Ajax call值未显示在 Servlet Ajax 调用的警报框中
【发布时间】:2013-10-21 08:48:22
【问题描述】:

我正在使用 ajax 按钮单击事件将一些值从 servlet 检索到 jsp 页面中。这里的事件响应在 firebug 中成功,但来自服务器端的值没有显示在警报框中这是我的代码..

JSP。

jQuery(document).ready(function() {
       var calltype;
   $('#scalltype').click(function(evt){
     evt.preventDefault();
     $.ajax({
     url: "Calltype",              
     type: "GET", 
     success: function(data){
     calltype=data;
     alert(calltype);
  },
  error:function(){
      console.log("AJAX request was a failure");
  }   
});});

这是我的 servlet 代码

ArrayList calltype = new ArrayList();
               while(rs.next()){
                   String toc=rs.getString("calltype");
                   calltype.add(toc);
                }

            out.print(calltype);
            System.out.println(calltype);
            out.close();

【问题讨论】:

  • 签入console.log(calltype);
  • @Riturajratan in console.log 值即将到来,但它没有进入警报框,为什么?
  • @Riturajratan 先生,如果我想使用这些值,我可以从 calltype 变量中使用
  • 查看更新并检查@vikas
  • @PeterRader 但 Calltype 是 servlet

标签: jquery ajax jsp servlets


【解决方案1】:

签到console.log(calltype);

因为在警报对象中没有出现所以在控制台中使用:)

更新

如果我想使用这些值,那么你可以使用 calltype 变量,例如

jQuery(document).ready(function() {
       var calltype;
   $('#scalltype').click(function(evt){
     evt.preventDefault();
     $.ajax({
     url: "Calltype",              
     type: "GET", 
     success: function(data){
     calltype=data;
     console.log(calltype);
    callbackfunction(calltype); //use in this your callback

  },
  error:function(){
      console.log("AJAX request was a failure");
  }   
});});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-08
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多