302 from an AJAX request - ajax

I send an AJAX request which returns a 302 (I see this using fiddler) but in firebug I never see the 302. I just see a 500.
Same thing happens with IE.
If an AJAX request returns a 302 do browsers swallow it?
Thanks

When performing an AJAX POST in my web application, I found that my browser was registering a 302 Found, followed by a 200 OK.
However, the JavaScript debugger showed the response as being a 200 OK, with the HTML content to be shown on the redirection page.
This demonstrates that the redirection is being handled internally by JavaScript. In this case, you could replace the page's content with that returned by the server's response.
document.open();
document.write(xhr.responseText);
document.close();
See this question for more details.

Related

JMeter POST request is returning 200 OK instead of 302 (redirect)

I'm attempting to login to a website that uses IdentityServer with JMeter but am getting stuck at the point where I post my credentials.
If I inspect the request via fiddler, I can see that it returns a 302 with a redirect, however when I attempt to post the same request in JMeter, I get a 200 with 'Error' in the html with no details.
This is my request in JMeter....
This is the request in Fiddler....
And this is the HTML response in JMeter (200 OK)...
And this is the Fiddler response...
And this is the HTML response in Fiddler, after the redirect...
I can confirm that my JMeter variables ${COOKIE_idsrv.xsrf} and ${SignIn are populated with the correct values.
Other points to note
I have a HTTP Cookie Manager
The HTTP Manager Referer headers are set correctly
All requests are set to Follow Redirects
I retrieve all embedded resources for each request
Does anybody know what could be the issue here?
In your POST request, why do you have "signin" parameter included?. You have already added "signin" as a query parameter and it appears to be redundant and not required for the actual POST body data. Fiddler does not have it in both the places. Please check.
After much frustration it turned out the issue was due to ${COOKIE_idsrv.xsrf} not containing the correct value for idsrv.xsrf. Once I changed this to pull it from a previous request it seemed to work okay.

Redirect issue jmeter for 301 and 302

I fired one URL on which redirection is expected but I am getting different response code in jmeter and on using devtools that is f12.
Example
Fired http://test.com on chrome, on using f12, i can see response code as 301 and in second line it displays 200 as successful redirection happened.
But, when same URL fired through jmeter, i got response code as 302(Found)
Right now, i have used HTTP request
Implementaion: No client selection(default),
GET,
Protcol - http and proxy server details.
Can you please let us know why we are able to see difference in response code when we fire that URL directly on chrome(301) and through jmeter(302)
Ensure that "Follow Redirects" is checked in your HTTP Request:

Ajax request redirect

I am doing a Ajax request, in the response depending on some condition. I might send a 301 status code with a location(redirect) URL. But when I do that there is a ajax request to the redirect URL, but I want it to be a normal request not a ajax request.
Is there a way to do that?
it's pretty easy, you might want the server to return an url instead of performing redirection, end then use window.location to perform redirection in javascript :).
Javascript can't see the redirect response, only the final response from the URL the browser was redirected to.
Javascript can try to recognize the situation by analyzing the response content: Maybe it expects JSON but gets HTML (e.g. a login page :-) )
To do it right you'd need to modify the service to return a non-redirect response code to the Javascript which it can then handle (e.g. 401 when the session expires and the user must log in again)

jQuery ajax call to domain that redirects to another domain (isn't followed)

This is sort of a cross-domain issue, but the problem is the browser (Chrome) doesn't seem to follow the redirect. Instead, nothing is returned to the jQuery ajax call, and I get an error.
I'm trying to use jQuery.ajax, but the URL that I'm using redirects to another domain. When this happens, I get an error. Is there anything special that needs to be done so the browser will follow the redirect?
I already added access-control-allow-origin: * to the header of the second domain that is being redirected to.
An HTTP redirect page is treated as any other HTTP page in that it also needs the access control headers. If your redirect page does not have them, the browser will never get around to checking if the page being redirected to has the proper permissions.
Along with the Location header on the redirect page, also add the Access-Control-Allow-Origin header and its related constituents (i.e. Access-Control-Allow-Methods etc.)
The only way to get a cross-domain ajax call is to use jsonp.
In jQuery, set your .ajax() dataType to 'jsonp'. See here: http://api.jquery.com/jQuery.ajax/
It still may not work, if the server being redirected to is not capable of a jsonp response. The difference between a json response and a jsonp response is that a json response is a pure json string, while a jsonp response is the code that calls a function passing in a json string.
A not-too-shabby tutorial: http://remysharp.com/2007/10/08/what-is-jsonp/
A good discussion: Can anyone explain what JSONP is, in layman terms?

How to find whether Ajax request successfully send by Fire-bug add-on?

Please can some one explain me how to use Fire-bug add-on to check about whether Ajax request successfully send from our application ???
When you turn on Firebug, there's tab called 'Network' - there are shown all requests, especially ajax. The network tab allows you to filter requests and check request/response headers, status code, and message.
So, if you turn on Firebug and open Network tab (it's possible you'll have to enable tracking first, in that case it will show appropriate message), you will see if there was a request, where you expected it should be.
To see only ajax requests, check XHR on top bar, just under general tabs.
It will display in 'console' tab in firebug. i show you ajax call and request. it show ajax request like if ajax is successful then is gives 200 request and display the data or if the ajax request if fails is gives you a 301 request or some other request.

Resources