How not to go to another page when using HTML forms with the action method:

<form method="post" action="http://api.forismatic.com/api/1.0/"> POST: <input type="text" name="method" value="getQuote"> <input type="text" name="key" value="457653"> <input type="text" name="format" value="text"> <input type="text" name="lang" value="en"> <input type="submit" name="sub"> </form> 

3 answers 3

assign a unique id to the form and fields.

change submit to button with the specified onclick="doAjax()" .

Where doAjax() is a function that performs a request for document.getElementsById('form_id').action and processes the result.

  • For some reason, does not work =) - AseN
  • entertaining ... the server returns 200 OK , but the contents of the page do not fall into the callback ... I am intrigued) now I will try to come up a bit from the other side - ikoolik
  • Yes, all right. I have already figured out. Thank you very much =) - AseN
  • My solution is to use my intermediate php file (so-so solution). And how did you solve the problem? - ikoolik

Probably use Ajax ..

    Submit form to iframe. It is only important that the action be on the same domain, otherwise the Same Origin Policy will not let you read the server response from this frame, then you have to resort to tricks (keywords for google: window.name-transport, location.hash-transport)