为了账号安全,请及时绑定邮箱和手机立即绑定

如何将参数从javascript传递给Ajax函数

如何将参数从javascript传递给Ajax函数

PHP
千万里不及你 2022-07-02 16:49:08
你好,我需要帮助,我有这个代码<a href="javascript:void(0);" onclick="removerow('.$row["sn"].');">     <i class="fa fa-remove" style="color: red"></i></a>我需要从onclick="removerow('.$row["sn"].')这个函数中获取价值function removerow() {    var vpb_sn = _______.val();}
查看完整描述

1 回答

?
波斯汪

TA贡献1811条经验 获得超4个赞

传递值:


onclick="removerow('.$row["sn"].');"

接受:


function removerow(value) 

{

    // and you can use it just like variable

    console.log(value);

}

将 var 发送到 php 文件(使用 jquery ajax):


function removerow(value) 

{

    $.ajax({

        url: 'index.php', // here path to php file

        type: 'post',  //type of a query

        data: {myVariable: value}, // data which sends into php file

        success: function (data) {

            alert('sended successfully!');

        }

    });

}

然后,在 index.php(发送数据的文件)中,我们可以使用以下命令查看我们的数据:


$_POST['myVariable'];


查看完整回答
反对 回复 2022-07-02
  • 1 回答
  • 0 关注
  • 148 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号