admin管理员组

文章数量:1302278

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); },
                      plete: function (xhr, status) { alert('plete: '+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);},
                      plete: function (xhr, status) { 
                          alert('jqXHR:'+xhr);
                          alert('plete: '+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

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); },
                      plete: function (xhr, status) { alert('plete: '+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);},
                      plete: function (xhr, status) { 
                          alert('jqXHR:'+xhr);
                          alert('plete: '+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

Share Improve this question edited Aug 8, 2013 at 18:20 AbtPst asked Aug 7, 2013 at 18:17 AbtPstAbtPst 8,01821 gold badges95 silver badges187 bronze badges 5
  • 1 I'm not positive on the java syntax, but that looks ok to me. What are you expecting to happen and what is happening instead? Did you check your javascript console and browser's network tab for errors? – Jason P Commented Aug 7, 2013 at 18:22
  • -1 for not showing actual behavior, error messages. Please take the time to put details in your questions, that will only help you so that more people look at your question – Ruan Mendes Commented Aug 7, 2013 at 18:29
  • thanks @Jason. I was hoping that the alert would pop up but it does not – AbtPst Commented Aug 7, 2013 at 18:35
  • thanks @Juan. i dont get any error messages. i just want to access the data sent by my gridedit.jsp thats why i was trying to pop up an alert to see whether any data is being passed or not. when i check the logs, the "ROW ROW ROW your boat" string gets printed. However I do not see the alert – AbtPst Commented Aug 7, 2013 at 18:37
  • If you are debugging in firefox, install the firebug add-on. There is a panel that can show the outgoing ajax request, and the response that (could) e back. – Shade Commented Aug 7, 2013 at 18:40
Add a ment  | 

2 Answers 2

Reset to default 4

Try number two:

I have an ajax request that looks like this:

$.ajax({
    url: "/someplace",
    dataType: "json",
    async: true,
    cache: false,
    data: {
        number0: 0,
        key: littleKey
    },
    success: function(data, status)
    {
        alert(data);
    }
});

and it works as is expected.

And you can specify get with type : "GET" in with the other options.

Maybe try having your .jsp print some data no matter what, and also print what data it is receiving.

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.

本文标签: javascriptHow to pass data to AJAX callStack Overflow