1

I am trying out JQuery and jqGrid for the first time to do a standard CRUD frontend to a database. Following documentation, I managed to get the adding rows to work but I would like to issue a success message. I tried this:

$("#list2").jqGrid('navGrid', '#pager2', {add:true, view:false, edit:false, del:false},
                   {},
                   {closeAfterAdd:true,
                    afterComplete: function(response, postdata, formid){
                            alert(response);
                    }
                   },
                   {},
                   {},
                   {});

The server side does the insert and echoes the success message that I'd like in the alert, but the alert dialog only says [Object object]. I would appreciate some help on how to handle the server response.

ravl1084
  • 291
  • 4
  • 11
  • Depends on the content. If server sends json, look for solution here: http://stackoverflow.com/questions/3334341/jquery-javascript-json-to-string-variable-dump – Alleo Sep 04 '11 at 13:31
  • found the error, it's `response.responseText` to get the server response. – ravl1084 Sep 04 '11 at 13:32
  • @Alleo it is not a JSON response in this case, simply an echo of a string. But because the reading of the JSON response for the data in the table is done behind the scenes, I didn't know how to take the response text manually – ravl1084 Sep 04 '11 at 13:57

2 Answers2

3

The first parameter of the afterComplete callback function has the same format as the first parameter of complete callback function of jQuery.ajax. So it's jqXHR or XMLHttpRequest (in case of usage old jQuery 1.4.x) depend of the used jQuery version.

So you should use alert(response.responseText) instead of alert(response).

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thank you. The type of the response object is exactly what I need to find to fiddle with it :) – ravl1084 Sep 04 '11 at 14:01
  • @ravl1084: You are welcome! I read just now that you have found the solution yourself. It' always better, because you will keep the knowledge much better in mind. – Oleg Sep 04 '11 at 14:05
0

You are alerting the response parameter itself, not any specific property on that object. I haven't used this callback before, but based on the documentation:

response is the data returned from the server (if any)

if you're returning any data from the server, you would refer to it as alert(response.<property>); instead of just alert(response).

Again, I haven't used this callback specifically, so I'm not sure if there's a wrapping property for the data you send back or not, but basically, you need to reference the specific property you want to display, and not the response object only.

UPDATE: I see from your comment that you found the answer. alert(response.responseText).

I hope this helps!

David Hoerster
  • 28,421
  • 8
  • 67
  • 102