parsererror status 'ok'. error code 200 - jqgrid

When i submit my JqGrid edit form, i am getting 'parsererror status 'ok'. error code 200' . can some one help me in getting to know why this error occurs, though i am getting response from server.
below are my codes
beforeShowForm: function(form){
$('#tr_ArticleID',form).hide();
$('#tr_ContractNo',form).hide();
},
url: "/JqGridDemo/prfArticle.do"
Also how should i get the response status (success / failed ) from server in a message box.
And how this submit button in jqGrid works??
i am using json here. many thanks.

Caution Wahab, You are parsing the HTTP Status Code. Doubtlessly, parsing OK will lead to an error. I don't know jqgrid but you need to fetch the response. Not the header information.

Related

500 error even request render HTML code

Using ajax to get HTML content from GSP template .
$.get(url,{word:$('#search').val()},fnback)
The browser Console raises 500 error .
However , we get the expected response , but in browser not in callback .
Known that this kind of error appears only in production environment .
This question is related to this ticket
The error is caused either by Grails or by your application, you will need to determine why; it certainly seems to be happening relatively late in the pipeline since you are getting the correct HTML back (I assume you aren't explicitly rendering a 500 status code in your code by accident).
As for the response you are getting back, it is ignored due to the 500 status. The $.get function accepts a callback which is only invoked on successful requests. If you put debug lines into your fnback function you will see it is never called. If you were to replace the $.get with an equivalent $.ajax call and provide an error callback, that function would get the HTML you are seeing returned in the browser's dev tools.
Based on #Gregor Petrin answer :
$.get(myurl,{word:word},function(d){
$('div#resp').html(d)
})
has been replaced by :
$.ajax({url:myurl,data:{word:word}}).always(function(d,status){
if(status !=='success'){
d=d.responseText;
}
$('div#resp').html(d);
});

ASP.NET MVC 4, ajax and exception details in JSON

I'm new to ASP.NET and MVC. In my controller I'm throwing ArgumentException on invalid user input. I like the fact that the client is getting some info back in JSON format. But I don't want to send the whole stacktrace, just the exception message (which contains a useful, localized explanation of the error).
How should I go about doing this?
I've seen some Application_Error() and FilterException, but they all seem to be redirecting to a special "error" view, whilst I want to stay on the same page and just print out a dialog with the user-friendly explanation.
Look at this answer ASP.NET MVC Ajax Error handling and also if you need StatusCode:
filterContext.HttpContext.Response.StatusCode = 500;
HttpContext.Response.StatusCode = 400
return new ContentResult{Content="My custom error"};
In this case ajax will treat response as in error state and you can specify your custom message and get to it from response.responseText property
$.ajax({
.....
error: function(e){
alert(e.responseText); // your error message
}
});

Using jqgrid, what is the best way to return errors from server side validation when using inline editing?

I am using jqgrid and using the inline editing mode and can't figure out how to return errors back to the client from server side validation rules
I use fluent validation on my serverside to validate before persisting to a database. This works great except I don't see how to return errors when editing in inline mode. If I don't persist the values to the databse, the client still shows the value which should be rejected.
What is the recommended way to return an error after someone commits an inline edit so you will get some popup on the client side showing the error and it will stay in edit state ?
NOTE: this image below is in response to Oleg's comment and answer below
The recommend way is to use any HTTP error code in the response on the submitting of wrong data and to return the error description in the body of the response. If you need some more specific action like displaying another dialog with the error information, setting of focus on a field, marking some fields with CSS class 'ui-state-error' or something like that you should use errorfunc callback function.
If restoreAfterError is false the inline editing will be continued.
UPDATED: I mention in comments that the server should produce the error message as the response. In case of ASP.NET MVC the default message is HTML text which you posted as the first picture. If you use HandleJsonExceptionAttribute which I described in my old answer the error message will be serialized as JSON, but it contains additional information which you don't need to display (like the StackTrace). So you should use errorfunc parameter of editRow or saveRow to decode the server response. You can either use decodeErrorMessage from the already referenced answer or use the $.parseJSON function directly:
errorfunc: function(rowid, res) {
var errorText = $.parseJSON(res.responseText).Message;
$.jgrid.info_dialog($.jgrid.errors.errcap,
'<div class="ui-state-error">' + errorText + '</div>',
$.jgrid.edit.bClose,
{buttonalign: 'right'});
}

Why is my json request erroring instead of succeeding?

Here is my debugging method that goes to the error block instead of the success block.
function removerelationship(reference_related_id_var) {
if ($('##relationships').attr('id') != undefined) {
$.ajaxSetup({cache:false});
$.ajax({
url: 'index.cfm?action=reference.confirmjson',
dataType: 'json',
data: {reference_id:reference_id_var, reference_related_id:reference_related_id_var},
success: function(){alert("I PASSED");},
error: function(){alert("I FAILED");}
});
But this is my response from calling reference.confirmjson:
{"MESSAGE":"Are You Sure You Want To Remove The Relationship Between References 744094 and 1200?","CONFIRMED":true}
Is there some reason this would still take me to the error block?
Thanks.
Make sure you have debug output turned off for the AJAX request . I explain it a bit better at http://orangexception.com/post/7308110027/remove-debug-output-from-ajax-requests-in-coldfusion
The error case would be called if any status other than a 200 is being returned. Take a peek at the response in Firebug or a similar tool. If CF is also throwing an error further down the request, it would return a 500. This can help you determine if you need to check the CF application log for an error.
Edit: Also, check the raw response. Firebug does an awesome job at dropping the trailing CF error and just showing the properly formatted JSON, which could be confusing if an error was thrown.

jquery ajax error json response

i have jquery global error event set, like following:
$("#message_alert").ajaxError(function(event, XMLHttpRequest, settings, thrownError){
ajax_error(XMLHttpRequest);
});
and ajax_error method gets the XMLHttpRequest parameter totally fine init. now the request which XMLHttpRequest gets, it also have json data from the backend in XMLHttpRequest.responseText
now i want to know, how can i parse this json data, i tried doing
eval("var request = "+XMLHttpRequest.responseText);
which for some reason was working fine, but dose not work anymore and i know for sure that data is getting back to ajax response. maybe something im doing wrong.. well firebug shows following error from it, i dont know what im doing wrong
Error:
missing ; before statement
http://basit.io.im/javascript/global.js
Line 127
btw this is the same eval line number. any ideas?
Have you tried -
eval("var request = XMLHttpRequest.responseText");
That should fix the error you are getting.

Resources