Cara menggunakan button reload page php

Berikut adalah cara merefresh halaman web namun hanya sebagian. Terkadang kita membutuhkan merefresh suatu bagian pada halaman website yang kita buat tanpa perlu mereload keseluruhan halaman. Hal ini berguna untuk mempercepat performa dari website atau sistem informasi kita. Ini umumnya digunakan pada saat mengupdate data lalu kita perlu melakukan refresh karena data telah berhasil dibuat. Berikut adalah simulasi refresh otomatis yang saya buat dengan menggunakan php, javascript, dan ajax. semoga bermanfaat

Caranya adalah sebagai berikut

1. Buat file index.php

<html>
<head>
<title></title>
</head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>  
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />  
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>  
<script type="text/javascript">
$(document).ready(function () {
	var id = 1;
    $("#refres").click(function () {
        $.ajax({
   url:"text.php",
   method:"POST",
   data:{id:id},
   success:function(data){
$('#Container').html(data);
alert('Berhasil Refresh');
   }
  });
    });
	
});
</script>
<body>
<button value="Refresh" id="refres">REFRESH</button>
<div id="Container" style="width:300px; text-align:center; height:100px; border: 1px solid black">
<?php include "text.php" ?>
</div>

</body>
</html>

2. Buat file text.php

File text.php ini adalah file yang akan di refresh. Kita dapat menggantinya dengan kode tampilan tabel database atau lainnya. Saya hanya menampilkan simulasi saja.

mohon bantuannya gan mas, saya masih belajar ni, saya membuat form edit codeigniter dan ajax, nah ketika proses edit data disitu saya menampilkan image pada form tersebut, saat saya mengganti image dan klik button update, image yang ada pada form tidak berubah, tetapi sudah ganti datanya. hanya tampilannya saja yg tidak berubah, imagenya tidak berbubah karena saya tidak reload formnya. pertanyaaannya bagaimana caranya saya mereload image tersebut tanpa reload page. berikut script yg saya gunakan.
function update()
{
   $('#btnSave').text('updating...'); //change button text
    $('#btnSave').attr('disabled',true); //set button disable 
    var url;

    url = "";
    // ajax adding data to database
    tinyMCE.triggerSave();
    var formData = new FormData($('#form')[0]);
    $.ajax({
        url : url,
        type: "POST",
        data: formData,
        contentType: false,
        processData: false,
        dataType: "JSON",
        success: function(data)
        {

            if(data.status) //if success close modal and reload ajax table
            {
                alert('Data Berhasil diUpdate');
                // location.reload();
            }
            else
            {
                for (var i = 0; i < data.inputerror.length; i++) 
                {
                    $('[name="'+data.inputerror[i]+'"]').parent().addClass('has-error'); //select parent twice to select div form-group class and add has-error class
                    $('[name="'+data.inputerror[i]+'"]').next().text(data.error_string[i]); //select span help-block class set text error string
                }
            }
            $('#btnSave').text('update'); //change button text
            $('#btnSave').attr('disabled',false); //set button enable 


        },
        error: function (jqXHR, textStatus, errorThrown)
        {
            alert('Error adding / update data');
            $('#btnSave').text('update'); //change button text
            $('#btnSave').attr('disabled',false); //set button enable 

        }
    });
}
contoh script yg saya guakan untuk menampilkan image di form

profil_image=="no_image.png"){?>

Cara menggunakan button reload page php

Update Clear

Cara menggunakan button reload page php

Use header() function to refresh a web page in PHP. The HTTP functions are those functions which manipulate information sent to the client or browser by the Web server before any other output has been sent. The PHP header() function sends an HTTP header to a client or browser in raw form. Before HTML, XML, JSON or other output has been sent to a browser or client, a raw data is sent with the request (especially HTTP Request) made by the server as header information. HTTP header provides required information about the object sent in the message body more precisely about the request and response.

Syntax:

void header( $header, $replace = TRUE, $http_response_code )
Or
header(string, replace, http_response_code)

Parameters:

  • $header: It holds the header string. There are two types of header calls. The first header starts with string “HTTP/”, which is used to figure out the HTTP status code to send. The second case of header is the “Location:”. It is mandatory parameter.
  • $replace: It is optional parameter. It denotes the header should replace previous or add a second header. The default value is True (will replace). If $replace value is False then it force multiple headers of the same type.
  • $http_response_code: It is an optional parameter. It forces the HTTP response code to the specified value (PHP 4.3 and higher).

Note: This function prevents more than one header to be sent at once. This is a protection against header injection attacks after PHP 4.4 release.

Below example illustrates the use of header() to refresh current page in PHP:

Example: This example uses header() function to refresh a web page in every 3 seconds.




<?php

  

// Demonstrate the use of header() function

// to refresh the current page

   

echo "Welcome to index page</br>";

echo <?php0;

<?php

<?php3

<?php4

<?php5<?php6<?php7

<?php

echo  0 1 2<?php7

  

 5;

 7

Output:

https://media.geeksforgeeks.org/wp-content/uploads/20190404004757/Untitled-Project.mp4

Example 2: This example uses header() function to redirect web page into another page.




<?php

  

// Demonstrate the use of header() function

// to refresh the current page

   

echo "Welcome to index page</br>";

echo // Demonstrate the use of header() function7;

<?php

// to refresh the current page0

<?php5// to refresh the current page2<?php7

<?php

 5;

 7

Output:

https://media.geeksforgeeks.org/wp-content/uploads/20190404005742/Untitled.mp4

References: https://www.php.net/manual/en/function.header.php

PHP is a server-side scripting language designed specifically for web development. You can learn PHP from the ground up by following this PHP Tutorial and PHP Examples.