Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.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
Javascript &引用;未捕获类型错误:对象#<;对象>;没有方法';可拖动'&引用;使用AJAX之后_Javascript_Jquery_Html_Ajax_Jquery Ui - Fatal编程技术网

Javascript &引用;未捕获类型错误:对象#<;对象>;没有方法';可拖动'&引用;使用AJAX之后

Javascript &引用;未捕获类型错误:对象#<;对象>;没有方法';可拖动'&引用;使用AJAX之后,javascript,jquery,html,ajax,jquery-ui,Javascript,Jquery,Html,Ajax,Jquery Ui,我目前正在使用jquery构建一个网页,我有可拖动的div。除了单击其中一个div以使用AJAX发送索引外,一切都正常。页面使用我从MySQL获得的新数据重新加载,但事件“draggable”、“sortable”和“droptable”给出以下错误: "Uncaught TypeError: Object #<Object> has no method 'draggable' " “未捕获的TypeError:对象”没有“可拖动”的方法 除了那些事件,一切都很顺利 下面是我的一

我目前正在使用jquery构建一个网页,我有可拖动的div。除了单击其中一个div以使用AJAX发送索引外,一切都正常。页面使用我从MySQL获得的新数据重新加载,但事件“draggable”、“sortable”和“droptable”给出以下错误:

"Uncaught TypeError: Object #<Object> has no method 'draggable' "
“未捕获的TypeError:对象”没有“可拖动”的方法
除了那些事件,一切都很顺利

下面是我的一些代码示例:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script type="text/javascript" src="plugins/calendar/jquery.datepick.js"></script>
<script type="text/javascript" src="js/jquery.ui.datepicker.js"></script>
<script type="text/javascript" src="js/validationPrescriptionNewConsole.js"></script> 
<script type="text/javascript" src="plugins/calendar/jquery.datepick.js"></script>
<script type="text/javascript" src="js/jquery.ui.core.js"></script>
<script type="text/javascript" src="js/jquery.ui.widget.js"></script>
<script type="text/javascript" src="plugins/balloon/jquery.balloon.js"></script>

(...)

$('#padroes').children().each(
    function(index, elem) 
    {
         $(elem).click(function(){

        $.ajax
        ({ 
            url: '***same page***',
            data: {indice: index, dt_ini: datepick1.value, dt_fim: datepick2.value },
            type: 'POST',
            success: function(output) 
            {
                $("body").html(output);     
            }
        });
    });
}); 
(...)

$(".jogos").draggable(
{ 
    cursor: "move",
    opacity: 0.7,
    revert: true,
    revertDuration: 50  
})

(...)
$('#padroes').children()。每个(
函数(索引,元素)
{
$(元素)。单击(函数(){
$.ajax
({ 
url:“***同一页***”,
数据:{indice:index,dt_ini:datepick1.value,dt_fim:datepick2.value},
键入:“POST”,
成功:功能(输出)
{
$(“body”).html(输出);
}
});
});
}); 
(...)
$(“.jogos”).draggable(
{ 
光标:“移动”,
不透明度:0.7,
回复:对,
有效期:50
})

提前感谢。

切勿在每个处理程序中定义单击函数。此外,您永远不会停止默认的单击事件

$('#padroes').children().click(function(e){  //add the e
    e.preventDefault(); //stop default behavior
    //your ajax call

});
此外,您正在使用
$('body').html(output)
,它随后将覆盖body中的所有现有数据,因此在页面加载时绑定到这些元素的任何处理程序将不再具有与它们关联的任何方法。您需要在
ajax成功函数中重新定义它们

success: function(output){
    $("body").html(output);
    $(output).find('.jogos').draggable({
        cursor: "move",
        opacity: 0.7,
        revert: true,
        revertDuration: 50  
    })
}

这应该可以解决问题。

为什么要调用
$(“body”).html(输出)结果如何?我有一个表单,当我单击一个按钮时,它会提交我的所有数据,但我只想在单击提交按钮之前提交索引以获取更多数据,因此我使用AJAX刷新页面,这样我只会得到$u POST[“indice”]的isset。我无法将表单放入表单。@scott.korin更新了…不知何故,我的帖子中的其余代码被截断了。我只是跳了枪,然后我想发送索引。这就是为什么我使用每个索引而不是立即单击。这并不能解决问题,在这行中给出了相同的错误$(输出).find('.jogos').draggable({光标:“移动”,不透明度:0.7,还原:true,还原持续时间:50})