javascript - jQuery - changing page with sending a POST parameter -
scenario is:
i have html a-tag in page(call 'index.php') link page (lets call page 'action.php') !
'action.php' page needs receive post parameter, otherwise return error!
i have needed parameter in 'index.php' page, dont want use form-tag send it. whenever user clicked on a-tag, parameter should sent 'action.php' page.
indeed, ajax has nothing here, while want change page, sending post parameter whenever user click on < > !
example: index.php
<a class='showproject' href='action.php' data-pid='<?php echo project_id ?>'> project </a>
action.php
echo $_post['project_id'];
i prefer that, if there way this, jquery code starts following event:
$('.showproject').on('click',this,function(e){ /* solution */ });
you can use ajax this. don't know have parameter want pass action.php, in example it's stored in hidden value.
$('.showproject').click(function() { var productid = $("#hiddenfield").value(); $.ajax({ type: 'post', url: 'action.php', data: {productid: productid}, success: function(data) { //do whatever need return data. }, error: function(xhr, ajaxoptions, thrownerror) { } }); });
Comments
Post a Comment