简体   繁体   中英

Submit hidden form value automatically?

How do I submit a specific part of the form automatically but without refreshing a page with the value attribute I need to send to server?

The reason I need to do this is to constantly check for match of email addresses from my database but without refreshing the pages....

I know I can use set interval to trigger a function every 0.25 seconds but what else should I insert so that my attribute will send to the server?

You can use on keyup event in jquery to get the text in the input field and send it to the server through ajax request.

<input type="text" id="email">

<script>
  $("#email").keyup(function(){

    $.ajax({
     url: "server_script.php?email="+encodeURIComponent($(this).val()),
     context: document.body
   }).success(function( response ) {
       // Server response will come here on success
       // Do what ever you like with the response
   });

 });
<script>

And in the server side get the email using $_GET['email'] and once the validation is done do something like echo "success";

<input id = "email">
<script>
$('#email').keydown(function(e){
    var email_value = e.target.value;
    $.post( "ur backend url", { "email": email_value } ).done(function(data){
           //respond here
        });
});
</script>

use keydown to trigger and ajax post to check the email.

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