简体   繁体   中英

How to call php function from anchor tag?

I am using a sweetalert popup. I am calling the function from anchor tag but it not taking any action. Would you help me out in this?

  <link rel="stylesheet" href="assets/css/sweetalert2.min.css">
  <script src="assets/scripts/sweetalert2.min.js"></script>
  <script src="assets/vendor/jquery/jquery.min.js"></script>
  echo ' <td class="btn-action"><a href="javascript:void(0);" onClick="record_delete('.$p_user_id.')" class="btn-delete"><i class="fa fa-times" aria-hidden="true"></i></a></td>';



  <script>
  function record_delete(id){
    swal({
     title: 'Are you sure?',
     text: "You want to move this record",
     type: 'warning',
     showCancelButton: true,
     confirmButtonColor: '#3085d6',
     cancelButtonColor: '#d33',
     confirmButtonText: 'Yes, move it!'
    },function () {
        window.location='process.php?function=p_delete&p_Id='+id+'';
    }); 
  }
  </script>

You need to quote p_user_id :

echo '<td class="btn-action"><a href="javascript:void(0);" 
          onClick="record_delete(\''.$p_user_id.'\')" class="btn-delete">
      <i class="fa fa-times" aria-hidden="true"></i></a></td>';

Identifier starts immediately after numeric literal.

This happens only when string in broken somewhere.

In this case it can only happen on 2 cases:

1) $p_user_id passed in the js function contains a single quote or double quote. For this Can you please share the id passed?

2) Your php statements are not wrapped inside php tags. For this please try:

<?php echo ' <td class="btn-action"><a href="javascript:void(0);" onClick="record_delete('.$p_user_id.')" class="btn-delete">asdfa</a></td>';?>

把你的锚变成这样的

<a href="javascript:record_delete("'.$p_user_id.'");return false'" class="btn-delete">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM