Conditional API Responses for JavaScript vs. HTML Forms: An Essential Guide
Too Long; Didn't Read
Today, I’ll show you how to detect whether an HTTP request was submitted via an HTML form or with JavaScript. When a form is submitted the browser sends the request as a page navigation, causing the next page to render whatever the server responds with. If the response is JSON, it will render that JSON string to the page. We can use this header to distinguish between one or the other.