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.
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: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.