简体   繁体   中英

Prevent page reload on form submit

I am trying to submit a form using get method but I dont want the form to refresh or rather when it reloads I want to maintain the data. There seems to be lot of questions on similar lines but none that I tried helped. I am posting my code here:

<script type="text/javascript">
 function formSubmit()
 {
     document.getElementById('form1').submit();
     return false;
 }
</script>


<form id = "form1" method = "GET">
    <br> Query:  <input name="query" id="query" type="text" size="50" value="">
   <input type="button" name="search" value="Get News" onclick = "formSubmit()">
</form>

I am using python on the server side.

Thanks

The statement:

    I am trying to submit a form using get method but I dont want the form  to 
refresh or rather when it reloads I want to maintain the data.

Implies to me that your end goal requires AJAX or at least some passing of data to the server and back. You will not be able to retain scope within Javascript over a page refresh without the use of something like cookies or passing data to/from the server. Having said that these are more akin to secondary storage mechanisms while you want to retain scope (or primary storage). To do this I would recommend AJAX.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM