Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery ui 将值传递给jQuery UI对话框,以便在确认时发布AJAX帖子_Jquery Ui_Jquery - Fatal编程技术网

Jquery ui 将值传递给jQuery UI对话框,以便在确认时发布AJAX帖子

Jquery ui 将值传递给jQuery UI对话框,以便在确认时发布AJAX帖子,jquery-ui,jquery,Jquery Ui,Jquery,我正在使用jQueryUI对话框确认删除请求。我试图在用户确认删除请求时将ID传递给AJAX帖子。提前感谢您提供的任何见解 以下是HTML: <table width="100%" cellspacing="1" cellpadding="5" border="0" class="detailTbl" id="myTable"> <tbody> <tr class="divider" id="editRow220"> <td align="top">

我正在使用jQueryUI对话框确认删除请求。我试图在用户确认删除请求时将ID传递给AJAX帖子。提前感谢您提供的任何见解

以下是HTML:

<table width="100%" cellspacing="1" cellpadding="5" border="0" class="detailTbl" id="myTable">
<tbody>
<tr class="divider" id="editRow220">
<td align="top">Lorem Ipsum is simply dummy text of the printing and typesetting industry. </td>
<td align="top">                                    
    <a class="btn_delete deleteMe form-tip" href="#" id="220" title="Delete this item"></a>
    <span>Lorem Ipsum is simply dummy text of the printing and typesetting industry. </span>
</td>
</tr>
</tbody>                                         
</table>

Lorem Ipsum只是印刷和排版行业的虚拟文本。
Lorem Ipsum只是印刷和排版行业的虚拟文本。
下面是脚本:

$("#myTable tbody").on("click", "a.deleteMe", function (e) {
    e.preventDefault();
    var RemoveID = $(this);
    alert(RemoveID.attr("id")); // ***correct ID here ***

    var $myDialog = $('<div></div>')
        .html('Are you sure you want to delete this item?')
        .dialog({
            autoOpen: false,
            title: 'Confirmation',
            buttons: {"Yes": function(e) { 
            alert(RemoveID.attr("id")); // ***RemoveID is undefined here*** 
                // AJAX Call here //

                return true;
            }, "No": function() {
          $(this).dialog("close");
                return false;
            }
  }
     });

    return $myDialog.dialog('open');
});
$(“#myTable tbody”)。在(“单击”、“a.deleteMe”上,函数(e){
e、 预防默认值();
var RemoveID=$(此值);
警报(RemoveID.attr(“id”);//***请在此处更正id***
变量$myDialog=$('')
.html('确实要删除此项目吗?')
.对话({
自动打开:错误,
标题:“确认书”,
按钮:{“是”:功能(e){
警报(RemoveID.attr(“id”);//***此处未定义RemoveID***
//在这里打电话//
返回true;
},“否”:函数(){
$(此).dialog(“关闭”);
返回false;
}
}
});
返回$myDialog.dialog('open');
});

这可能是一个草率的解决方案,但您能否尝试将ID分配给全局变量,然后使用它:

var mID;

$("#myTable tbody").on("click", "a.deleteMe", function (e) {
e.preventDefault();
mID = $(this).attr("id");

var $myDialog = $('<div></div>')
    .html('Are you sure you want to delete this item?')
    .dialog({
        autoOpen: false,
        title: 'Confirmation',
        buttons: {"Yes": function(FmoPmoToRemove) { 
             alert(mID); //shouldnt be undefined anymore

..rest of code.. 
var-mID;
$(#myTable tbody”)。在(“单击”,“a.deleteMe”,函数(e)上{
e、 预防默认值();
mID=$(this.attr(“id”);
变量$myDialog=$('')
.html('确实要删除此项目吗?')
.对话({
自动打开:错误,
标题:“确认书”,
按钮:{“是”:函数(FmoPmoToRemove){
警报(mID);//不应再未定义
…代码的其余部分。。

我在jsFiddle www.jsFiddle.net/bphamous/rQ3MC上做了一个简单的moch,它似乎正在工作。问题一定在我的代码中。

像这样使用Java脚本的cofirm()时有什么问题:

function delete(Id){
   boolean b = confirm("Deleting : "+Id", Are you sure ..??");
   if(b == true){
    // make the delete process here ...
   }
   else{
      // do dtuff .....
   }
 }

为什么不将id本身捕获到变量中,而不是整个对象中?
var RemoveID=$(this.attr('id');
如果在$.post()函数之前写了“return”,请使用return(true或false)在Callback中,如果对话框不是DOM的一部分,我认为它不能被“打开”。例如,
return$myDialog;
在您的代码中返回对话框的那一行,比如
$('body')。append($myDialog);$myDialog.dialog('open'));
我只是更新了代码,在使用jQuery UI对话框之前,一切都正常。它在这里工作是JSFIDLE,我在使用Javascript确认()时没有问题。我试着在jQuery UI对话框按钮函数回调中。我成功了。你可以在这里查看它。听着……在jQuery UI对话框中有一种添加按钮的方法,你可以添加cacnel按钮并将其编程为“取消删除”,你可以添加按钮删除并将其编程为“删除”,明白吗???