weixin_33701251 2013-08-07 18:17 采纳率: 0%
浏览 40

如何将数据传递给AJAX调用

Can anyone tell me how to pass data to the jsp making the AJAX call ? This is what I am trying:

Here is my AJAX call:

     $.get("gridedit.jsp", { before: "row", time: "2pm" })
               .done(function(data) {
                 alert("Data Loaded: " + data);
               });

here is my gridedit.jsp

    <% String b=request.getParameter("before");

    if(b.equalsIgnoreCase("row"))
     {
System.out.println("ROW ROW ROW your boat");
        out.println("bummer");
    } %>

i want to store the value returned from gridedit.jsp into a javascript variable. How should I do this ?

please help

thanks

EDIT:

here is what i also tried

    $.ajax({
                url: "gridedit.jsp",

                async: true,
                cache: false,
                type:"GET",
                data: {
                    before:'row',
                      },
                      error: function(msg) { alert(msg); },
                      complete: function (xhr, status) { alert('complete: '+status); }

            });

i get two alerts, the first one says

    [object][object]

and the second one says

    error

can anyone figure out whats going on ?

please help

thanks

Errors;

so here i what i tried

      $.ajax({
                url: "gridedit.jsp",
                //dataType: "json",
                async: true,
                cache: false,
                type:"GET",
                data: {
                    before:'row'
                      },
                      error: function( jqXHR, textStatus, errorThrown ) { alert(jqXHR);
                      alert(textStatus);
                      alert(errorThrown);},
                      complete: function (xhr, status) { 
                          alert('jqXHR:'+xhr);
                          alert('complete: '+status); }

            });

i get the following alerts in order:

jqXHR: [object][object]

testStatus:

      parseerror

errorthrown:

      Unexpected end of input

can anyone please help me in solving this ? my gridedit.jsp does this->

          <%String b=request.getParameter("before");
          System.out.println("b is here !" + b);
                        out.println("HELLO");%>

please help

thanks

  • 写回答

2条回答 默认 最新

  • 零零乙 2013-08-07 18:24
    关注

    It is in a variable, the data variable in the anonymous function passed to .done()

    Whatever you need the data returned by gridedit.jsp to do, the easiest way to have anything done with it is to use it in that function. Right now all you are doing with it is making a popup containing the returned data.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器