php - let a forum in a div reload without the page reloading -


i curious know if it's possible can have div reload window does. reason have forum don't want full page reload after 4 completed. wondering if elements in div or forum section background reload or load them self when submit button pressed.

this in file called forum information gets typed in. want not reload page stay on forum , still send data database.

<html>      <body>                <form action="demo.php" method="post" />              <p>input 1: <input type="text" name="firstname" /></p>              <input type="submit" value="submit" />          </form>            <div id = "load_results"></div>      </body>  </html>

this sending information database want done discreetly.

<?php  $servername = "localhost";  $username = "root";  $password = "root";  $dbname = "mydb";    // create connection  $conn = new mysqli($servername, $username, $password, $dbname);  // check connection  if ($conn->connect_error) {      die("connection failed: " . $conn->connect_error);  }     $value = $_post['firstname'];    $sql = "insert myguests (firstname) values ('$value')";      if ($conn->query($sql) === true) {      echo "<a href=https://twitter.com/angela_bradley>my twitter</a>";  } else {      echo "error: " . $sql . "<br>" . $conn->error;  }    $conn->close();  ?>

yes, there way. called ajax - but, not worry, it's pretty simple.

your code this:

html:

<form action="demo.php" method="post" />     <p>input 1: <input type="text" name="firstname" /></p>     <input type="submit" value="submit" /> </form> 

js/jquery:

$(function(){     $('form').submit(function(evt){     //next line stops form submission sending `demo.php`     evt.preventdefault(); //evt stands "event" - can anything. use e.preventdefault()     var fn = $('[name=firstname]').val();     $.ajax({         type: 'post',          url: 'demo.php', //send data demo.php -- page stays         data: 'first='+fn,         success: function(d){             if (d.length) alert(d);         }     }); //end ajax }); //end document.ready 

demo.php

<?php     $fn = $_post['fn'];     //do database insert here      //if wish, can return data ajax's success function:     echo 'you submitted: ' .$fn; 

here posts simple ajax examples:

ajax request callback using jquery


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -