Merhabalar.
Butona tıkladığım zaman ajax ile arka plandan güncelle .php ye gidip orda güncelleme yapması lazım.
herhangibir değer post etmicem. bütün işlemi arka plandan guncelle.php yapıcak.
guncelle .php de hit diye bir değerim var. id değerim ile birlikte "UPDATE posts SET hit = hit + 1 WHERE id = 1" şeklinde sorgu içinde veriyorum. ek bir veri yollamıyorum. sadece tetikleyici lazım.
Nasıl Yapabilirim?
PHP ve Ajax İle Güncelleme İşlemi
10
●336
- 12-07-2022, 12:03:47Teşekkürler fakat bir sorum var.byroot adlı üyeden alıntı: mesajı görüntüle
Sadece update.php ye gitmesini ve işlemimi çalıştırmasını istiorum. Nasıl yapabilirim. - 12-07-2022, 12:07:58Özür dilerim yazılımda yeniyim. sorularım saçma gelebilir ama hala class ı update olan butona tıklayınca şu dosyaya git çalıştır nasıl derim ?byroot adlı üyeden alıntı: mesajı görüntüle
:/ - 12-07-2022, 12:23:20Teşekkürler. Fakat sanırım bir yerde yanlışlık yapıyorum. Yardımcı olabilirsen sevinirim.byroot adlı üyeden alıntı: mesajı görüntüle
index.php
<input type='submit' value='update' onSubmit="update()" />
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0w wj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script>
function update(){
$.ajax({
url:"update.php", //Dosya yolu
type:"POST",
data:, //Göndereceğin data
success:function(){
//yapmasını istediğin işlem
}
});
}
</script>
update.php
<?php
require 'mysql.php';
$id = 1;
$sorgu = $db->prepare("UPDATE tablom SET hit = hit +1 WHERE id='".$id ."' ");
$sorgu->execute(array($id));
?> - 12-07-2022, 23:15:35update.php
require 'mysql.php'; if (isset($_POST['process'])) { $process = $_POST['process']; if ($process = 'update') { $id = 1; $sorgu = $db->prepare("UPDATE tablom SET hit = hit +1 WHERE id='".$id ."' "); $sorgu->execute(array($id)); } if ($process = 'delete') { //other processes } if ($process = 'add') { //other processes } }index.php
<button type="button" id="up" >Update</button> <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0w wj1yYfoRSJoZ+n" crossorigin="anonymous"></script> <script> $(document).ready(function(){ $("#test").click(function(){ var process = "update"; $.ajax({ type:"POST", url:"update.php", data:{process: process}, success: function(data){ } }); }); </script>
