I’m trying to submit a form as a POST request with pre-loaded data to a site with no API. I have wrapped my form inside an iframe element, hoping to isolate it. However, the page still changes to the action page. How can I trap it in to prevent this?
Some answers to similar questions suggest setting the response’s Content-Type to text/plain to force the browser to treat it as a document instead of a file. However, please note that I don’t have access to the other end.
No need to wrap the
formin aniframe. Keep the form on the main page and create a hidden, separateiframeon the same page. Then you need to use the form’stargetattribute to let theiframebecome the target for the result of the POST operation. This way when submitting theformyou will stay on the page, and the results will get loaded into theiframe.This blog should help and also the answer to this question.