I need some help with figuring out how to pass a jquery var (which used to be a php var), to a ui dialog and then transform that var into PHP var.
我需要一些帮助,找出如何将一个jquery var(曾经是一个php var)传递给一个ui对话框,然后将该var转换为PHP var。
On my adminstration.php I have some radio buttons with a value pulled from my database.
在我的adminstration.php上,我有一些带有从我的数据库中提取的值的单选按钮。
With some jQuery that changes the value according to which of the radio button that has been pressed:
使用一些jQuery根据已按下的单选按钮更改值:
function select_user(){
var id = null;
$('input[name="user_id"]').on("click", function(){ //This is the radio button
if ($(this).prop("checked", true)) {
var id = $(this).val();
$("#delete_user").prop("href", "delete_user.php?id=" + id);
}else{
var id = null;
return false;
}
});
}
What I'm looking for is, to take that user_id and pass it to the dialog by pressing a delete button: Delete
我正在寻找的是,通过按下删除按钮获取user_id并将其传递给对话框:删除
What I think I've figured out is that I need to use .data() (I'm not sure though, cause it hasn't work so far). However, I was trying to change the "delete_user.php?id=3" for example, but I couldn't figure out if I was on the right track or not.It looks something like this.
我想我已经想到的是我需要使用.data()(我不确定,因为它到目前为止还没有工作)。但是,我试图更改“delete_user.php?id = 3”,但我无法弄清楚我是否在正确的轨道上。它看起来像这样。
$("#delete_user").click(function() {
$("#dialog-placeholder").load("delete_user.php").dialog({
resizable: false,
height: "auto",
modal: true,
buttons: {
"Delete user": function() {
$( this ).dialog( "close" );
},
Cancel: function() {
$( this ).dialog( "close" );
location.reload(true);
}
}
});
});
Because I'm not writing PHP in object (and have no idea how to), I'm writing it in the "old" way, so it's all in the same page. I then somehow need to take that jquery var caught in the dialog and change it into a php var.
因为我不是在对象中编写PHP(并且不知道如何),所以我是以“旧”的方式编写它,所以它们都在同一页面中。然后我以某种方式需要在对话框中捕获jquery var并将其更改为php var。
If there are anyone who can point me in the right direction, it's very much appreciated.
如果有人能指出我正确的方向,我们非常感激。
1 个解决方案
#1
0
If you want your button to activate a php function, you must use an ajax request. so to pass the variable to php, package it in your ajax request.
如果您希望按钮激活php函数,则必须使用ajax请求。所以要将变量传递给php,将其打包在你的ajax请求中。
<script>
var someJqueryVar;
var url="targat.php?val="+someJqueryVar;
$.ajax( url )
//...
</script>
#1
0
If you want your button to activate a php function, you must use an ajax request. so to pass the variable to php, package it in your ajax request.
如果您希望按钮激活php函数,则必须使用ajax请求。所以要将变量传递给php,将其打包在你的ajax请求中。
<script>
var someJqueryVar;
var url="targat.php?val="+someJqueryVar;
$.ajax( url )
//...
</script>