Create See Other response from web api

203 Views Asked by At

I have a button on website to download a pdf. On click of it, I will hit a POST API which will create a lead and redirect to another url (pdf location) on success. I am using SeeOther Http status (303) for this.

How can I return 303 response from web api? How to handle it in jquery ajax?

Current API approach:

Response.Headers.add("Location", pdfUrl);
return StatusCode(HttpStstusCode.SeeOther);

Not sure how to handle ajax response as it is coming in ajax fail block.

1

There are 1 best solutions below

0
On

This is standard behaviour. If you check the jQuery source for $.ajax, you'll see that a request is counted as 'successful' when the HTTP status code is:

isSuccess = status >= 200 && status < 300 || status === 304;

This is why your 303 response is going in to the error handler. You either need to handle the response there, or use a different HTTP response code.