Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to continuously update a part of the page

http://pastebin.com/dttyN3L6

The file that processes the form is called upload.php

I have never really used jquery/js so I am unsure how I would do this or where I would put the code.

It has something to do with this setInterval (loadLog, 2500);

Also, how can I make it so the user can submit a form without the page refreshing?

 $.ajax({  
  type: "POST",  
  url: "upload.php",  
  data: dataString,  
  success: function() {  

  }  
});  
return false;  `

and

 <?php 
 $conn1 = mysqli_connect('xxx') or die('Error connecting to MySQL server.');
 $sql = "SELECT * from text ORDER BY id DESC LIMIT 1";
 $result = mysqli_query($conn1, $sql) or die('Error querying database.');
 while ($row = mysqli_fetch_array($result)) {
      echo  '<p>' . $row['words'] . '</p>';
 }
 mysqli_close($conn1);

 ?>

 </div>

 <?php     
 if (!isset($_SESSION["user_id"])) {

 } else {
      require_once('form.php'); 
 }

 ?>
like image 959
Web Owl Avatar asked May 08 '12 03:05

Web Owl


People also ask

How do you automatically update sections in Word?

Update all fields in a documentPress F9. If your document has tables with fields or formulas, you might need to select each table separately and press F9. Tip: To make sure that you don't forget to update your table of contents before you print the document, set Word to update fields automatically before printing.

What is a continuous section break in Word?

A Continuous section break starts the new section on the same page. Tip: You can use Continuous section breaks to create pages with different number of columns. An Even Page or an Odd Page section break starts the new section on the next even-numbered or odd-numbered page.

How do I update fields in Word?

Updating fields To update a field manually, right-click the field and then click Update Field or press F9. To update all fields manually in the main body of a document, press Ctrl + A to select all and then press F9. Some fields in headers, footers or text boxes must be updated separately.

What is a section break?

Section breaks enable you to split a document into several sections, enabling you to apply different formatting and layouts to each section. For instance, having two sections in a document enables one section to have portrait orientation and the other to have landscape orientation.


1 Answers

You can submit a form without refreshing a page something like this:

form.php:

<form action='profile.php' method='post' class='ajaxform'>
 <input type='text' name='txt' value='Test Text'>
 <input type='submit' value='submit'>
</form>

<div id='result'>Result comes here..</div>

profile.php:

<?php
      // All form data is in $_POST

      // Now perform actions on form data here and 
      // create an result array something like this
      $arr = array( 'result' => 'This is my result' );
      echo json_encode( $arr );
?>

jQuery:

jQuery(document).ready(function(){

    jQuery('.ajaxform').submit( function() {

        $.ajax({
            url     : $(this).attr('action'),
            type    : $(this).attr('method'),
            dataType: 'json',
            data    : $(this).serialize(),
            success : function( data ) {
                        // loop to set the result(value)
                        // in required div(key)
                        for(var id in data) {
                            jQuery('#' + id).html( data[id] );
                        }
                      }
        });

        return false;
    });

});

And If you want to call an ajax request without refreshing page after a particular time, you can try something like this:

var timer, delay = 300000;

timer = setInterval(function(){
    $.ajax({
      type    : 'POST',
      url     : 'profile.php',
      dataType: 'json',
      data    : $('.ajaxform').serialize(),
      success : function(data){
                  for(var id in data) {
                    jQuery('#' + id).html( data[id] );
                  }
                }
    });
}, delay);

And you can stop the timer at any time like this:

clearInterval( timer );

Hope this will give you a direction to complete your task.

like image 169
Naveed Avatar answered Sep 18 '22 10:09

Naveed