Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/473.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/9/security/4.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
在submit中使用javascript和ajax调用创建表单_Javascript - Fatal编程技术网

在submit中使用javascript和ajax调用创建表单

在submit中使用javascript和ajax调用创建表单,javascript,Javascript,我的ajax调用中有一个小问题,我将解释: 我有一个页面(article.php),其中有一个按日期和公司查找项目的页面,我调用了一个ajax页面“action/SearchArticle.php”,该页面返回结果,我在我的页面article.php上看到了海报 在结果中,我修改了一个按钮,当我单击时,我在一个带有Javascript的弹出窗口中创建了另一个要更改的列,这是我的问题:我想在这个弹出窗口中单击submit时,我对PHP页面进行ajax调用以修改部分,但它不起作用 我是这样做的 $(

我的ajax调用中有一个小问题,我将解释:

我有一个页面(article.php),其中有一个按日期和公司查找项目的页面,我调用了一个ajax页面“action/SearchArticle.php”,该页面返回结果,我在我的页面article.php上看到了海报

在结果中,我修改了一个按钮,当我单击时,我在一个带有Javascript的弹出窗口中创建了另一个要更改的列,这是我的问题:我想在这个弹出窗口中单击submit时,我对PHP页面进行ajax调用以修改部分,但它不起作用

我是这样做的

$(document).ready(function () {
    $('#result #modifier').click(function () {
        // récuperer le id article
        var popINC = $(this).attr('rel');
        // récuperer commentaire article
        var popComment = $("#result #comment" + popINC).text();
        //créer le commentaire
        var comment = '<label for="comment">Commentaire</label><input type="text" id ="comment" name="comment" value="' + popComment + '"/>';
        //créer une checkbox pour id_article
        var inpInc = "<input type='checkbox' id='flag' name='flag[]' value='" + popINC + "'>" + popINC;
        //construire le formulaire avec le id_article et commentaire
        var contenu = '<form action="" method="post" id="changeFlag"><ul><li>' + inpInc + '</li><li>' + comment + '</li><button type="submit">Chercher</button></ul></form>';
        // Afficher popup
        $('#' + popID).html(contenu).fadeIn().css({
            'width': Number(popWidth)
        });
        var popMargTop = ($('#' + popID).height() + 80) / 2;
        var popMargLeft = ($('#' + popID).width() + 80) / 2;
        $('#' + popID).css({
            'margin-top': -popMargTop,
            'margin-left': -popMargLeft
        });
        $('body').append('<div id="fade"></div>'); //Ajout du fond opaque noir
        //Apparition du fond - .css({'filter' : 'alpha(opacity=80)'}) pour corriger les bogues de IE
        // Cacher la page HTML
        $('#fade').css({
            'filter': 'alpha(opacity=80)'
        }).fadeIn();
        return false;
    });
    $('a.close, #fade').live('click', function () { //Au clic sur le bouton ou sur le calque...
        $('#fade , .popup_block').fadeOut(function () {
            $('#fade, a.close').remove(); //...ils disparaissent ensemble
        });
        return false;
    });
    // Quand je clique sur mon formulaire modifier article crée dans la 1er partie
    $("#changeFlag").submit(function () {
        var dataString = $(this).serialize();
        $.ajax({
            type: "POST",
            url: "../action/test.php",
            dataType: 'html',
            data: dataString,
            success: function (response) {
                if (response) {
                    alert('dede');
                } else {
                    $("#result").text("Errodr");
                }
            }
        });
        return false;
    });
 });
$(文档).ready(函数(){
$(“#结果#修饰符”)。单击(函数(){
//récuperer le id文章
var popINC=$(this.attr('rel');
//récuperer评论文章
var popComment=$(“#结果#注释”+popINC).text();
//评论杂志
var comment='Commentaire';
//créer une复选框pour id_文章
var inpInc=”“+popINC;
//解释公式和注释
var contenu='
  • '+inpInc+'
  • '+comment+'
  • Chercher
'; //粘贴器弹出窗口 $('#'+popID).html(contennu.fadeIn().css({ “宽度”:数字(popWidth) }); var popMargTop=($('#'+popID).height()+80)/2; var popMargLeft=($('#'+popID).width()+80)/2; $('#'+popID).css({ “页边距顶部”:-popMargTop, “左边距”:-popMargLeft }); $('body').append(“”);//Ajout du noir //幻影du found-.css({'filter':'alpha(不透明度=80)})倒在走廊上 //缓存页面HTML $('#褪色').css({ “过滤器”:“alpha(不透明度=80)” }).fadeIn(); 返回false; }); $('a.close,#fade').live('click',function(){//Au clic sur le bouton ou sur le calque。。。 $('#淡入,.popup#u块')。淡出(函数(){ $(“#淡入,a.close”).remove();/…ils不同集成 }); 返回false; }); //“我的权利集团”修正条款第1部分 $(“#changeFlag”).submit(函数(){ var dataString=$(this.serialize(); $.ajax({ 类型:“POST”, url:“../action/test.php”, 数据类型:“html”, 数据:dataString, 成功:功能(响应){ 如果(答复){ 警惕(“dede”); }否则{ $(“#结果”)。文本(“Errodr”); } } }); 返回false; }); });
结果:当我点击提交时,弹出页面刷新,然后我什么都没有


提前感谢

问题是,提交事件处理程序在创建
变更标志
表单之前已注册。因此,您需要更改提交事件注册以使用事件委派模型

如果使用jquery<1.7,请使用

如果jQuery>=1.7,则使用


在控制台中,将其设置为在页面导航中保留错误,并查看有哪些JavaScript错误。仅供参考:LIve在1.7+中已被弃用,在1.9+中已被删除,请停止使用它。选择器
$(“#结果#修饰符”)
很差,只需使用
$(“#修饰符”)
$("#changeFlag").live('submit', function () {
    var dataString = $(this).serialize();
    $.ajax({
        type: "POST",
        url: "../action/test.php",
        dataType: 'html',
        data: dataString,
        success: function (response) {
            if (response) {
                alert('dede');
            } else {
                $("#result").text("Errodr");
            }
        }
    });
    return false;
});
$(document).on('submit', '#changeFlag', function() {
    var dataString = $(this).serialize();
    $.ajax({
                type : "POST",
                url : "../action/test.php",
                dataType : 'html',
                data : dataString,
                success : function(response) {
                    if (response) {
                        alert('dede');
                    } else {
                        $("#result").text("Errodr");
                    }
                }
            });
    return false;
});