dsfhd78978 2015-02-18 16:17
浏览 175
已采纳

如何使用$ .ajax将变量传递给alert()?

I want to let the user confirm to deletion of a record by letting them click on the button and the button sends the value Yes to a $_POST request so I can delete the record with PHP, instead it's showing me the javascript file that contains the function.

What am I doing wrong, I've been tinkering and searching for 3 hours straight, while in the back of my mind I know it's a easy fix.

Any help is greatly appreciated.

If you think there is a smarter way to be doing this, please let me know.

$(function () {

    $("#DeleteConfirm").dialog({

        buttons: {
                 "Confirm": function() {
                    var DeleteConfirmation = "Yes";                 
                    $.ajax({
                        type: "POST",
                        url: "index.php",
                        data: DeleteConfirmation,
                        success: function(DeleteConfirmation){
                            alert(DeleteConfirmation);
                        },
                        dataType: "text"
                    });

                 },
                 "Cancel": function() {
                     $(this).dialog("close");
                 }
             }
    });

});
  • 写回答

3条回答 默认 最新

  • duanqiao9541 2015-02-18 16:33
    关注

    Javascript:

    if( confirm('Are you sure?')){
        /*proceed?*/
    }
    

    That is standard javascript. It wraps your AJAX call within the braces and if the user clicks 'yes' - the ajax call will execute. If he click 'no', then nothing happens. The confirm() prompt pops up an alert on screen with buttons. The resulted is captured by the if. You can also capture the result of that: var res=confirm('are you sure?');.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题