Reputation: 43
My user will be access ../verify.php?code=1228119j8dwq8dj218
and i want the 1228119j8dwq8dj218
passed to /verify_action.php
I've tried something like below but it says code
is undefined,
when i tried to place my verify-action.php
script in the verify.php
and change url:"verify-action.php"
to url:"verify.php"
it working perfectly but causing my success and error message not showing properly
AJAX
<script>
$(document).ready(function(){
$.ajax({
url:"verify-action.php",
method:"GET",
data:{code:code},
success:function(data)
{
if(data.error !== '')
{
$('#message').html(data.error);
}
if(data.success != '')
{
$('#message').html(data.success);
}
}
})
});
</script>
PHP
$error = '';
$success = '';
if(isset($_GET["code"]))
{
$object->query = "
UPDATE user_table
SET email_verify = 'Yes'
WHERE user_verification_code = '".$_GET["code"]."'
";
$object->execute();
$success = '<div class="alert alert-success">Your Email has been Verified</div>';
}else{
$error = '<div class="alert alert-danger">Verify Error. Please Contact Administrator</div>';
}
$output = array(
'error' => $error,
'success' => $success
);
echo json_encode($output);
?>
Upvotes: 0
Views: 1084
Reputation: 43
const urlParams = new URLSearchParams(window.location.search);
var code = urlParams.get('code');
Simple solution is just to get the URL parameter using that script Thanks to @broomber
Upvotes: 1