Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/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
Php 在对话框jquery中尝试使用ajax删除字段时返回错误_Php_Jquery_Ajax_Jquery Ui Dialog - Fatal编程技术网

Php 在对话框jquery中尝试使用ajax删除字段时返回错误

Php 在对话框jquery中尝试使用ajax删除字段时返回错误,php,jquery,ajax,jquery-ui-dialog,Php,Jquery,Ajax,Jquery Ui Dialog,我有调查列表,每个都有编辑按钮,当点击时,按钮对话框弹出数据库中的答案,这些答案有删除按钮,但我无法让它们工作。这是我的密码。 JQUERY: $( "#dialog1" ).dialog({ autoOpen: false, width:'auto', open: function(event, ui){ $('<button>', { 'class': 'button' }) .ap

我有调查列表,每个都有编辑按钮,当点击时,按钮对话框弹出数据库中的答案,这些答案有删除按钮,但我无法让它们工作。这是我的密码。 JQUERY:

 $( "#dialog1" ).dialog({ 
    autoOpen: false,
    width:'auto',

   open: function(event, ui){
       $('<button>', {
            'class': 'button'
        })
        .appendTo($(".wrapper"))
        .click(function(){

            var prom=$(this).closest('div').attr('id') ;
            alert(prom);
          $.ajax({
                url: 'admin/deleteField',
                type: 'post',
                data: { idanswer: prom} ,
                success: function () {
                alert("success");

                },
                error: function () {
                    alert("error");

                }
            });
        });
});
HTML

    <?php
    $answers=$survey->AllAnswers;
    foreach($answers as $answ)
    {
?>
<div class="wrapper" id="<?php echo $answ['Id']; ?>" style="width:auto;">
<input id='answers' name='answers[]' type='text' value='<?php echo $answ['Answer']; ?>'>    
<?php } ?>


当我点击某个答案的删除按钮时,警报(“错误”)会显示一秒钟,然后对话框关闭,什么也没发生

好的,所以我添加了return false;在ajax调用结束时,它开始工作了

 $( "#dialog1" ).dialog({ 
autoOpen: false,
width:'auto',

open: function(event, ui){
   $('<button>', {
        'class': 'button'
    })
    .appendTo($(".wrapper"))
    .click(function(){

        var prom=$(this).closest('div').attr('id') ;
        alert(prom);
      $.ajax({
            url: 'admin/deleteField',
            type: 'post',
            data: { idanswer: prom} ,
            success: function () {
            alert("success");

            },
            error: function () {
                alert("error");

            }
        });
return false;
    });
});
$(“#dialog1”).dialog({
自动打开:错误,
宽度:'自动',
打开:功能(事件、用户界面){
$('', {
“类”:“按钮”
})
.appendTo($(“.wrapper”))
。单击(函数(){
var prom=$(this).closest('div').attr('id');
警报(prom);
$.ajax({
url:'admin/deleteField',
键入:“post”,
数据:{idanswer:prom},
成功:函数(){
警惕(“成功”);
},
错误:函数(){
警报(“错误”);
}
});
返回false;
});
});

答案::删除答案(IdAnswer);
应该是
答案::删除答案($IdAnswer)
哦,这是一个输入错误,我只是编辑了它!但这不是它,在我的代码中是正确的。tnx!我认为你应该检查你的urlurl绝对是好的,我检查了它,tnx!好的,所以我只是在ajax调用的末尾添加了
return false;
并且它工作了!!不知道确切的原因,但很好,tnx@Awlad Liton和@sayali感谢你的帮助!
 $( "#dialog1" ).dialog({ 
autoOpen: false,
width:'auto',

open: function(event, ui){
   $('<button>', {
        'class': 'button'
    })
    .appendTo($(".wrapper"))
    .click(function(){

        var prom=$(this).closest('div').attr('id') ;
        alert(prom);
      $.ajax({
            url: 'admin/deleteField',
            type: 'post',
            data: { idanswer: prom} ,
            success: function () {
            alert("success");

            },
            error: function () {
                alert("error");

            }
        });
return false;
    });
});