0

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

HTML

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

查询

  $(".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");

});

}

我怎么能这样做?谢谢

4

1 回答 1

1

您在click 事件中定义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");

});
于 2013-10-28T10:24:43.723 回答