Monday 15 September 2014

How to show data from database without refreshing the page using jquery, PHP -


Is using the jury to load newly entered rows in the database without refreshing the page? I can send data to refresh the database without any life, but I am stuck in displaying that data without refreshing the page. How can I show data in a table without fresh page and it appears in index.php under the table, which I want to display the recoverable data? Thanks

This is my index.php

  & lt; Html & gt; & Lt; Top & gt; & Lt; Script src = "jquery.js" type = "text / javascript" & gt; & Lt; / Script & gt; & Lt; Script type = "text / javascript" & gt; $ (Document) .ready (function () {$ ('# submit'). (Function () {$ .ajax ({type: "POST", url: 'send.php', data: "user = Val () + "& amp; Comment =" + $ ('# comment'). Val (), Success: Function (Data) {$ ('input [type = text] ') .val (' ') $ (' # condition '). Html (data);}});});}); & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Div & gt; & Lt; Input type = "text" name = "user" id = "user" & gt; & Lt; Input type = "text" name = "comment" id = "comment" & gt; & Lt; Input name = "submit" type = "submit" id = "submit" & gt; & Lt; Div id = "condition" & gt; & Lt; / Dv> & Lt; / Div & gt; & Lt; Br> & Lt ;? Php $ con = mysqli_connect ("localhost", "root", "", "user"); // Check connection if (mysqli_connect_errno ()) {echo "failed to connect to MySQL:". Mysqli_connect_error (); } $ Result = mysqli_query ($ con, "comments from selection"); Echo "& lt; table width = '640' & gt; & lt; tr & gt; & lt; / tr & gt;"; While ($ line = mysqli_fetch_array ($ result)) {resonant "<<" Echo "& lt; td style = 'vertical-alignment: text-top' & gt;" . $ Line ['user'] "& lt; / td & gt;"; Echo "& lt; td & gt; & lt; br & gt; & lt; br & gt; & lt; br & gt; . Word Verb ($ line ['comment'], 90, '
is true). "& Lt; / td & gt;"; Echo "& lt; / tr & gt;"; } Resonates "& lt; / table & gt;"; Mysqli_close ($ thief); ? & Gt;

And this is my send.php that submits data to the table.

  & lt ;? Php $ mysqli = new mysqli ("localhost", "root", "", "user"); If ($ mysqli-> connect_errno) {echo "failed to connect to MySQL: (" MySqli-> Connect_errno. ")". $ Mysqli- & gt; Connect_error; } $ Username = $ _POST ["user"]; $ Comment = nl2br ($ _ POST ['comment']); $ Stmt = $ mysqli- & gt; Prepare ("Enter comments (user, comment) value (?,?)"); $ Stmt- & gt; Tie-On ('s', $ username, $ comment); $ Stmt- & gt; Executed (); Echo "Comment posted successfully"; ? & Gt;    

Using jQuery AJAX and PHP to get data from a MySQL database For a brief example. JQuery AJAX allows us to update the page content without reloading the page:



No comments:

Post a Comment