1

I am trying an AJAX call inside the

       beforeSelectRow

event of my grid as :

      beforeSelectRow: function(rowid, e) {

            $.ajax({
                url: "gridedit.jsp",
                dataType: "json",
                async: true,
                cache: false,
                type:"GET",
                data: {
                    before:'row',
                      },
                success: function(data, status)
                {
                    alert(data);
                }
            });
            return true; 
        }

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 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 apache tomcat logs, the "ROW ROW ROW your boat" string gets printed. However I do not see the alert when i select a row.

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

AbtPst
  • 6,676
  • 13
  • 69
  • 138
  • If you capture the network traffic (using Fiddler, Chome's Network developer tool tab, etc) what do you see? Are you seeing the expected result from your server? – Michael Freake Aug 07 '13 at 21:21
  • hi @Michael Freake, i can check the tomcat logs and everything looks ok. if i call success: function(data, status) { alert(status); } – AbtPst Aug 07 '13 at 21:50
  • thenthe alert shows 'error' ! can you think of any reason why my status is being returned as error ? – AbtPst Aug 07 '13 at 21:50

3 Answers3

1

Your JSON may not be formatted properly. Try returning a quoted string, such as "\"ROW ROW ROW your boat\"".

Justin Ethier
  • 122,367
  • 49
  • 219
  • 273
  • i want to return "bummer". should it not pop up in the alert ? the problem is that my ajax status shows error which means the call was not completed successfully. at least the part where it was supposed to get the data. please look at the edit above – AbtPst Aug 08 '13 at 15:05
  • The error function takes 3 args, its type signature is: `Function( jqXHR jqXHR, String textStatus, String errorThrown )`. Try alerting on all of them to see what is happening, or even better, debug and setting a breakpoint inside the `error` function. – Justin Ethier Aug 08 '13 at 15:11
  • thanks i tried what you said. please look at the edit. i explain what error i am getting – AbtPst Aug 08 '13 at 18:13
  • You may need to set the proper JSON mime type, see: http://stackoverflow.com/questions/249692/jquery-wont-parse-my-json-from-ajax-query – Justin Ethier Aug 08 '13 at 18:39
1

Try this.

beforeSelectRow: function(rowid, e) {
 $.ajax({
                url: "gridedit.jsp",
                async: true,
                cache: false,
                type:"GET",
                data: {
                    before:'row',
                      },
                success: function(data, status)
                {
                    alert(data);
                }
            });

        }

gridedit.jsp

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

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

Hope this helps Thank you

SarathSprakash
  • 4,484
  • 2
  • 16
  • 32
0

i figured out what was wrong. my gridedit.jsp had some code at the top which was creating some extra headers. i removed it and now it works fine.

AbtPst
  • 6,676
  • 13
  • 69
  • 138