0

I have a simple script that prompts the user to confirm delete, then it just alerts them that the process was completed properly.

I tried using jConfirm and the Javascript console spits out: "ReferenceError: jConfirm is not defined"

<!-- jConfirm --> 
// the script is referenced properly    
<script src="/js/jconfirm/jquery.jconfirm-1.0.min.js"></script>


<script>
function careersDelete(career_id) {
  jConfirm('Are you sure you want to delete this career?', 'Delete Career', function (x) {
    if (x) {
        jQuery.ajax({
            url: "ajax_career_delete.php",
            type: "GET",
            data: "career_id=" + career_id,
            success: function (response) {
                alert('Career deleted');
            }
        });
    }
});

}

On the button that should enable the confirm dialog, I have:

<a href="#" onclick="careersDelete('<?php echo $career_id; ?>')">delete</a>
4

1 回答 1

2

如果您查看这些示例,您会发现您需要单独源 jquery,并且 jconfirm 仅在其命名空间中定义。因此,您需要在代码中添加两件事:

<script src="/js/jquery.js"></script> <!-- or wherever jquery.js's path is -->
...
  $.jconfirm('Are you sure  ...
  // note jquery's $. namespace; and the non-capitalized "c" in jconfirm

此外,$.jconfirm函数调用不需要字符串。它的签名是:

function(options, callback)

并且callback不使用任何参数执行(因此您x将是undefined)。看起来您想要的内容类似于:

function careersDelete(career_id) {
  jQuery.jconfirm({
       message: 'Are you sure you want to delete this career?',
       title: 'Delete Career'
  }, function () {
        jQuery.ajax({
            url: "ajax_career_delete.php",
            type: "GET",
            data: "career_id=" + career_id,
            success: function (response) {
                alert('Career deleted');
            }
        })
  });
}
于 2014-07-16T12:54:06.890 回答