jquery - Execute PHP code onclick of button/link? -
i have shopping cart uses php. when person adds cart, relevant code done @ top of cart.php, meaning have leave product page add cart, , end having press button if want more.
how execute php/sql code when user clicks "add cart", without redirecting them new page? think jquery/json needed here, don't know first thing that. below:
//product page <input type="button" value="3"/> //when button clicked, sql/php based on value on same page
originally, had:
//product page <form action="./cart.php" method="post"> //some code user select whats submitted <input type="submit"/> </form> ... //cart page //some logic relevant taking value product page , adding cart //then display cart contents
the problem takes them new page when i'm positive logic can done on same page onclick of button.
do post
request jquery,the page doesn't load since ajax..
$('input[type="submit"]').on('click',function(){ var data = $('your_input_element').val(); $.post('./cart.php',{"data" :data},function(response) { console.log(response); }); });
or:
give target
form
iframe
hidden
//product page <form action="./cart.php" method="post" target="iframe_target"> //some code user select whats submitted <input type="submit"/> </form> <iframe id="iframe_target" name="iframe_target" src="#" style="display:none;"></iframe>
Comments
Post a Comment