0

Hey guys I am still a newbie in ajax. I have a problem with running JavaScript when the button clicked. All I want is, if I clicked the button I can run ajax so ajax can call PHP script and do query, at the same time can change page.

This is my html code

<input type="button" onclick="detailbayar()" value="Saya Sudah Bayar" data-theme="b">

function detailbayar()
{
        $.ajax({
                url: host+'/skripsi3/phpmobile/tenantmembayar.php',
                data: { id: user,id1:getacara,id2:getorderID},
                dataType: 'json',
                success: function(result){
                    alert("Payment Accepted");
                    window.location.href="detailpesanan.html";
                },
                error: function(){
                    //output.text('There was an error loading the data.');
                }
            });

}

and this is my PHP code

<?php
session_start();
include "config.php";

$idtenant=mysql_real_escape_string($_POST["id"]);
$idacara=mysql_real_escape_string($_POST["id1"]);
$orderID=mysql_real_escape_string($_POST["id2"]);
date_default_timezone_set('Asia/Jakarta');
$tanggal = date("d M Y G:i");
$bayar="telahbayar";
$konfirmasi="On Process";

$query="UPDATE `preorder` SET `tanggalbayar`='$tanggal',`statuspesanan`='$konfirmasi',`statusbayar`='$bayar'   WHERE id_tenant='$idtenant' && id_acara='$idacara' && id_order='$orderID'";
$result = mysql_query($query);
?>

Sorry for my bad English, Thank You and have a nice day.. Cheers!!

Wowsk
  • 3,637
  • 2
  • 18
  • 29
Rei
  • 143
  • 1
  • 11

1 Answers1

0

If the page changes before your request is completed, your request will be terminated. To achieve your purpose, you can use a form. Set action property of the form to /skripsi3/phpmobile/tenantmembayar.php. Change the button into a submit button for the form. At the end of tenantmembayar.php, add a line to redirect the browser to the page you want to go to.

Read PHP Redirect to another page after form submit

v7d8dpo4
  • 1,399
  • 8
  • 9
  • hey @v7d8dpo4 thank you for your answer, i am sorry i don't get it. Can u give me an example please? or an reference? Thank you – Rei Apr 24 '16 at 15:08