dqxz96998 2013-09-12 06:55
浏览 32

使用多个ajax请求删除帐户

The user, upon clicking a button(delete) is given the option to delete his account-he must enter his password also to do that. So I am describing above the 1st ajax request which is made.WHat is returned from the server is a response if there are still bookings(it is a booking web app) made from the user and if he should reconsider-a message appears.

If he insists deleting his account then he must click the delete button again. The problem(if you have not noticed) is that by clicking again the delete button the above procedure is repeated while the aim now-after the warning message appears-is that the click of the delete button means "yes, despite the bookings I want to delete my account".

So, this delete button must have dual role, one before the warning appear and one after the warning. What can I do in a situation like this?I was thinking implementing a confirm box but the above are all taking place in a modal box.So a confirm box over a modal I do not think is the correct solution.

Here is the ajax request that is sent when the user first clicks the delete button:

  $('.deactivate').click(function(){
     event.preventDefault();

        var trimmeddelpass=$.trim($('input#del_password').val());

  if(trimmeddelpass!=="")
        {   $.ajax({
           type: "POST",
           url: "delaccountajax.php",
           data: {"delpass":trimmeddelpass},
           success:function(data){
           if(data==2)
           {$('#warning').html('You have still bookings pending');
            $('#warning').show();
             }
           else if(data==3)
        { window.location.href = "../Frontend/login.php";//proceed deleting the account
            }

           error:function(jxhr){ 
           alert(jxhr.responseText);}
           });
        }

Here is the server code:

  $output=delete_account($conn,$delpass,$sessionml);
  if($output=='2')
  {$success='2';}
  elseif($output=='3')
  {logout();
  $success='3';}
  echo $success;

Both of the codes above are simplified versions involved since some other stuff were in them too,-they are not needed though for the issue we are dealing.

I have problem implementing the code you propose...it is the right solution of course but...look what is going on,here is the code:

  $('.deactivate').click(function(){
     event.preventDefault();
   deletestate=0;
 if(deletestate==0)

           { $.ajax({
           type: "POST",
           url: "delaccountajax.php",
           data: {"delpass":trimmeddelpass},
           success:function(data){
           if(data==2)
           {$('#warning').html('You have booking pending');
            $('#warning').show();
            deletestate=1
            }....
if(deletestate==1){....}

The code above always set the global deletestate to 0,setting it to 1 later has no effect whatsoever...how can i do this?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 Revit2020下载问题
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
    • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数