确认对话框后的Jquery ui转到ajax帖子

时间:2013-10-28 10:19:16

标签: jquery jquery-ui

我以这种方式用ajax $ post调用删除了我的记录

HTML

$btn = "<input type='button' ";
$btn .= "url='$_SERVER[REQUEST_URI]' idric='$row[id_ric]' ancor='#LR'";
$btn .= "class='deletr ttip' />";

JQUERY

  $(".delete").click(function(){

       var ancor = $(this).attr('ancor');
       var url = $(this).attr('url');
       var idric = $(this).attr('idric');

       var url = url + ancor;

    $.post("testpost.php", {url:url, idric:idric}, function(data){

         location.reload();

    });
});

testpost.ph

//class delete
$obj->delete($_POST['id_ric']);

我想在确认对话框后删除记录。 我试过这种方式但没有成功。

  $(".delete").click(function(){

    html_msg = "Are u sure?";

    var ancor = $(this).attr('ancor');
    var url = $(this).attr('url');
    var idric = $(this).attr('idric');

    var url = url + ancor;

    $('#confirm').dialog('open').html(html_msg);
  });

  $("#confirm").dialog({
        resizable: false,
        autoOpen: false,
        modal: true,
        dialogClass: 'confirm',
        buttons: {
            Yes: function() {
              $(this).dialog( "close" );
             testdelete();
        },
            No: function() {
              $(this).dialog( "close" );

        }
     }
});

function testdelete(){

 $.post("testpost.php", {url:url, idric:idric}, function(data){

    //location.reload();
    alert("ok");

});

}

我怎么能这样做?感谢

1 个答案:

答案 0 :(得分:1)

您将urlidric定义为delete点击事件中的局部变量。移除它们前面的var它应该有效。目前testdelete函数不知道urlidric是什么。

  $(".delete").click(function(){

    html_msg = "Are u sure?";

    var ancor = $(this).attr('ancor');
    url = $(this).attr('url');
    idric = $(this).attr('idric');

    url = url + ancor;

    $('#confirm').dialog('open').html(html_msg);
  });

  $("#confirm").dialog({
        resizable: false,
        autoOpen: false,
        modal: true,
        dialogClass: 'confirm',
        buttons: {
            Yes: function() {
              $(this).dialog( "close" );
             testdelete();
        },
            No: function() {
              $(this).dialog( "close" );

        }
     }
});

function testdelete(){

 $.post("testpost.php", {url:url, idric:idric}, function(data){

    //location.reload();
    alert("ok");

});