Paano ko irereplace

loktoy

Established
pano ko kaya irereplace tong code ng jquery dito sa code sa


echo "<script>window.location.href='admin/dashboard.php';</script>";
} else {
echo "<script>window.location.href= 'user/voucher.php';</script>";

ito code ko sa jquery

<!-- <script>
jQuery(document).ready(function() {
jQuery("#login_form").submit(function(e) {
e.preventDefault();
var formData = jQuery(this).serialize();
jQuery.ajax({
type: "POST",
url: "<?php echo $_SERVER['PHP_SELF']; ?>",
data: formData,
success: function(html) {
if (html == 'true') {
jQuery.jGrowl("Welcome Back!", { header: 'Access Granted' });
var delay = 2000;
setTimeout(function() {
window.location = './user/voucher.php'
}, delay);
} else {
jQuery.jGrowl("Please Check your username and Password", { header: 'Login Failed' });
}
}
});
return false;
});
});
</script> -->
 
To replace the jQuery code with PHP code, you can modify the original PHP code as follows:

PHP:
<?php
if (/* your condition here */) {
    header("Location: admin/dashboard.php");
    exit();
} else {
    header("Location: user/voucher.php");
    exit();
}
?>

This PHP code uses the header() function to redirect the user to the desired page. The exit() function is used to stop the execution of the script after the redirection.

Note that you need to replace /* your condition here */ with the actual condition that determines whether the user should be redirected to the admin dashboard or the user voucher page.
 
To replace the jQuery code with PHP code, you can modify the original PHP code as follows:

PHP:
<?php
if (/* your condition here */) {
    header("Location: admin/dashboard.php");
    exit();
} else {
    header("Location: user/voucher.php");
    exit();
}
?>

This PHP code uses the header() function to redirect the user to the desired page. The exit() function is used to stop the execution of the script after the redirection.

Note that you need to replace /* your condition here */ with the actual condition that determines whether the user should be redirected to the admin dashboard or the user voucher page.
pano ko po iinsert dyan yun jquery..

ito code na to qt sya naa mag reredirect sa page nya

<!-- <script>
jQuery(document).ready(function() {
jQuery("#login_form").submit(function(e) {
e.preventDefault();
var formData = jQuery(this).serialize();
jQuery.ajax({
type: "POST",
url: "<?php echo $_SERVER['PHP_SELF']; ?>",
data: formData,
success: function(html) {
if (html == 'true') {
jQuery.jGrowl("Welcome Back!", { header: 'Access Granted' });
var delay = 2000;
setTimeout(function() {
window.location = './user/voucher.php'
}, delay);
} else {
jQuery.jGrowl("Please Check your username and Password", { header: 'Login Failed' });
}
}
});
return false;
});
});
</script> -->
 
pano ko po iinsert dyan yun jquery..

ito code na to qt sya naa mag reredirect sa page nya

<!-- <script>
jQuery(document).ready(function() {
jQuery("#login_form").submit(function(e) {
e.preventDefault();
var formData = jQuery(this).serialize();
jQuery.ajax({
type: "POST",
url: "<?php echo $_SERVER['PHP_SELF']; ?>",
data: formData,
success: function(html) {
if (html == 'true') {
jQuery.jGrowl("Welcome Back!", { header: 'Access Granted' });
var delay = 2000;
setTimeout(function() {
window.location = './user/voucher.php'
}, delay);
} else {
jQuery.jGrowl("Please Check your username and Password", { header: 'Login Failed' });
}
}
});
return false;
});
});
</script> -->
To insert the jQuery code into your PHP code, you can do the following:

PHP:
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Process your form data here
    $username = $_POST['username'];
    $password = $_POST['password'];
    
    // Perform your validation and authentication logic here
    $isValid = /* your validation and authentication logic */;
    
    if ($isValid) {
        echo json_encode(['status' => 'true']);
        exit();
    } else {
        echo json_encode(['status' => 'false']);
        exit();
    }
}
?>

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
    jQuery(document).ready(function() {
        jQuery("#login_form").submit(function(e) {
            e.preventDefault();
            var formData = jQuery(this).serialize();
            jQuery.ajax({
                type: "POST",
                url: "<?php echo $_SERVER['PHP_SELF']; ?>",
                data: formData,
                success: function(response) {
                    var data = JSON.parse(response);
                    if (data.status === 'true') {
                        jQuery.jGrowl("Welcome Back!", { header: 'Access Granted' });
                        var delay = 2000;
                        setTimeout(function() {
                            window.location = './user/voucher.php';
                        }, delay);
                    } else {
                        jQuery.jGrowl("Please Check your username and Password", { header: 'Login Failed' });
                    }
                }
            });
            return false;
        });
    });
</script>

In the PHP code, you can process your form data, perform validation and authentication logic, and return the result as JSON.

In the jQuery code, the form is submitted using AJAX. The response from the server is parsed as JSON, and based on the status received, the appropriate message is displayed and the redirection is performed.

Note that you need to replace /* your validation and authentication logic */ with your actual validation and authentication code to determine if the login is valid or not.
 

About this Thread

  • 3
    Replies
  • 313
    Views
  • 1
    Participants
Last reply from:
Unknown user

Online now

Members online
980
Guests online
1,020
Total visitors
2,000

Forum statistics

Threads
2,276,167
Posts
28,968,006
Members
1,231,151
Latest member
eeyjee
Back
Top