Run PHP file without updating the page

Asked

Viewed 2,059 times

-1

I have a list of products, when clicking on some product, will go to another PHP file and do the calculations and go back to the products page.

But if I click on a product that is close to the footer, that is, at the bottom of the page, when I return to this product page, the user will go back to the top of the site because the page has been updated.

How to execute commands of another PHP file when clicked on an IMAGE without refreshing the page?

You can put some example, like: PRODUCT IMAGE

File (verifies.php) will do:

<?php
$credito = "30.00";
$id = $_GET['id'];
$valor = $_GET['valor'];
if($valor > $credito){ 

echo "<script type='text/javascript' language='javascript'> alert ('Você ultrapassou seu limite de crédito!'); window.location.href='carrinho.php'; </script>";

}else{

header("Location: produtos.php");

}

?>

That is, when you go back to products.php page you will refresh the page, you can not refresh the page?

  • 1

    You need to use Ajax. Some examples here, here, here and here.

  • Use AJAX, will solve your problem.

  • Can you put an example like: <a href="check.php? id=1&value=20.00">PRODUCT IMAGE</a> File (verifies.php) will do: <? php $credito = "30.00"; $id = $_GET['id']; $value = $_GET['value']; if($value > $credito){ echo "<script type='text/javascript' language='javascript'> Alert ('You have exceeded your credit limit!'); window.location.href='cart.php'; </script>"; }Else{ header("Location: products.php"); } ? > That is, when you go back to products.php page you will refresh the page, you cannot refresh the page?

1 answer

0

Dude what you can do is put the scripts of the products that are giving error on the same page if possible, if you put the code would be easier to understand.

  • So, it is not giving error, only if the user clicked on a product that is there below the screen, as soon as finished processing the user goes back there at the top, ie updated the page...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.