Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 未捕获类型错误:对象没有方法';停止即时复制';_Php_Javascript_Ajax_Jquery - Fatal编程技术网

Php 未捕获类型错误:对象没有方法';停止即时复制';

Php 未捕获类型错误:对象没有方法';停止即时复制';,php,javascript,ajax,jquery,Php,Javascript,Ajax,Jquery,未捕获的TypeError:对象没有方法“stopImmediatePropagation” 这是我从9lessons网站上获得的完整代码 $(document).ready(function() { $(".delete").live('click',function() { var id = $(this).attr('id'); var b=$(this).parent().parent(); var dataString

未捕获的TypeError:对象没有方法“stopImmediatePropagation”

这是我从9lessons网站上获得的完整代码

$(document).ready(function()
{
    $(".delete").live('click',function()
    {
        var id = $(this).attr('id');
        var b=$(this).parent().parent();
        var dataString = 'id='+ id;
        if(confirm("Sure you want to delete this update? There is NO undo!"))
        {
            $.ajax({
                type: "POST",
                url: "delete_ajax.php",
                data: dataString,
                cache: false,
                success: function(e)
                {
                    b.hide();
                    e.stopImmediatePropagation();
                }
            });
        return false;
        }
    });
}
错误指向
e.stopImmediatePropagation()


如何解决此错误?谢谢

您需要在clickhandler中包含事件对象:

 $(".delete").live('click',function(e)

传递给success函数的第一个变量应该是数据对象,而不是事件。似乎您想抓住点击事件并取消它,因为您正在处理它。因此,在顶部,使用以下内容:

$(".delete").live('click',function(event)
{
    event.stopImmediatePropagation();
    ...everything else...
});
并移除原始e.stopImmediatePropagation()

这应该可以

$(document).ready(function()
{
$(".delete").live('click',function(evt)
{
var id = $(this).attr('id');
var b=$(this).parent().parent();
var dataString = 'id='+ id;
if(confirm("Sure you want to delete this update? There is NO undo!"))
{
    $.ajax({
type: "POST",
url: "delete_ajax.php",
data: dataString,
cache: false,
async: false,
success: function(e)
{
b.hide();
evt.stopImmediatePropagation();
}
           });
    return false;
}
});

注意
async:false,这将使代码执行等待Ajax完成,并停止单击事件。您无法从异步成功处理程序停止事件。

e
在您的代码中是Ajax响应,而不是事件对象。您到底想做什么?Ajax请求没有您希望停止其传播的事件始终第一步是检查jQuery文档。有关
$.ajax
,请参阅
success
,了解它接受哪些参数。如果这是9lessons网站的代码,您需要停止从中学习该行位于
success
回调函数中