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

你好,我需要帮助,我有这个代码


<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();

}


千万里不及你
浏览 149回答 1
1回答

波斯汪

传递值:onclick="removerow('.$row["sn"].');"接受:function removerow(value)&nbsp;{&nbsp; &nbsp; // and you can use it just like variable&nbsp; &nbsp; console.log(value);}将 var 发送到 php 文件(使用 jquery ajax):function removerow(value)&nbsp;{&nbsp; &nbsp; $.ajax({&nbsp; &nbsp; &nbsp; &nbsp; url: 'index.php', // here path to php file&nbsp; &nbsp; &nbsp; &nbsp; type: 'post',&nbsp; //type of a query&nbsp; &nbsp; &nbsp; &nbsp; data: {myVariable: value}, // data which sends into php file&nbsp; &nbsp; &nbsp; &nbsp; success: function (data) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert('sended successfully!');&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; });}然后,在 index.php(发送数据的文件)中,我们可以使用以下命令查看我们的数据:$_POST['myVariable'];
打开App,查看更多内容
随时随地看视频慕课网APP