4xx Response from server doesn't include JSON data - ajax

I've got a .NET MVC site that uses JSON to perform AJAX form Posts. If a validation error occurs (ie user misses a required field etc), then the server returns the validation errors in a JSON object and sets the HTTP status code of the response to something in the 400 range. On our local machines, this works absolutely fine.
However on our CI environment, it has suddenly stopped working, without any code changes. The response comes back from the server with the correct HTTP code, but the content is not the JSON our controller returns, but the standard .NET error page HTML, ie just the 11-byte 'Bad Request' response if the status code is 400.
The error code is correct for each validation error, so we are hitting the right controller/action, and the validation is working correctly, but for some reason our JSON is getting snipped out. Any ideas why this might be happening?

You are getting 400 code because your request syntax in not correct. Check if you have actually encode json data correctly or not.

Related

express graphql always sends 500 Internal server error for any thrown error from resolver

I am using express graphql in my node app . and it graphql always sends 500 Internal server error for any thrown error from resolver. Please suggest any solution so i will get proper response and status code
The express-graphql sends the HTTP error 500 whenever detects there is no data returned. Definitely, in case of exception is thrown there won't be a returning data. Although it looks like an obvious bug the developers have their own opinion on that. They seemed to decide providing an option to disable the feature so that the server shouldn't set the 500 error. At least the open issue on that is still there.
Checking out the sources I've found these options to get around the problem:
To set any other response code than 200 (e.g. 299 (custom)) in your resolver.
To set the response code in your error formatting handler. This seems to be the most optimal solution.
Just to pick up some other library =)

variable "_method" is not defined in s3demo.php

I am using fine uploader. for the server side handling using s3demo.php,(downloaded from github).
But while sending response to this file, there are error that, $_POST['_method'] is not defined.
can any body give me solution for this problem ?

Got "parsererror" when trying to using Ajax call REST Service

I have been puzzled by this question for almost a week and still not able to get it solved.
The problem is while using JS Ajax calling a REST GET method, but I always got
parser error
However it's working fine for Firefox's REST Client
Check the Code here.
The URL http://wally.pythonanywhere.com/test/ is not producing a valid JSONP. Valid JSONP response should look like your json data wrapped in a function invocation. Visit JSONP doc for more details.
The actual error your code facing is "jQuery18308228800671640784_1374132969407 was not called". This is because of the invalid JSONP response.

What error to return if method expects only ajax calls?

What HTTP status should action return if it expects to only be used via AJAX, but was called without proper ajax headers? I feel I should signify some error, but I can't really find appropriate one.
I guess best would be 405 Method not allowed, but it would be weird if for example ajax GET requests returned content, and plain GET would return 405.
You can fulfill the request, but you refuse to do it since it's not in AJAX, so I think the appropriate error is 403 - forbidden.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.4
Anyways, I don't think any error code will be weird if it'll be accompanied with a clear explanation.

How to debug a failed ajax request in google chrome?

I have a web application that crashes on ajax requests with google chrome (it works with every other web browser it was tested it). After debugging I found that the error is caused by response.responseText being undefined. The xhr object looks like this:
argument: undefined
isAbort: false
isTimeout: undefined
status: 0
statusText: "communication failure"
tId: 3
In debugger in the 'network' tab I get "(failed)", however all the headers are there and I can even copy into clipboard the response body (which is a valid JSON).
My question is - how can I debug this problem? Where to find additional information, what causes this request to fail?
I finally found the solution to my problem : AdBlocks, when it blocks an ajax request, it just says "communication failure".
The first thing I would double-check is that the data coming back from the response is valid JSON. Just pass it through a JSON validator like this online JSONLint: http://jsonlint.com/
I assume that you are using something like jQuery to make your AJAX requests. If so, then make sure that you are using the development version of that library. Now that you are using the development version (uncompressed) of the script, find the particular function that you are using (eg. $.ajax) and then, within the Chrome inspector, insert a breakpoint in the code where the AJAX response is first handled (eg. https://github.com/jquery/jquery/blob/master/src/ajax.js#L579). Then proceed to step through the code, inspecting various return-values to see exactly what is going wrong.
If you are not using something like jQuery to make AJAX calls, then I'd recommend using a framework to avoid possible cross-browser compatibility issues like you might be experiencing right now.

Resources