.post()返回ID不受页面Jquery的影响

.post() return ID not being affected by pages Jquery

本文关键字:Jquery 影响 返回 ID post      更新时间:2023-09-26

这个问题与我在这里问的问题直接相关:停止点击()在ajax创建的输入上发生

我通过简单地添加if(e.target===this)就找到了答案,但现在当我选中复选框时,我返回的响应不会起任何作用。

我的帖子返回的新代码是:

$output .= "<table><tr><td>";
$output .= "<input id='"toedit'" type='"text'" placeholder='"$item_to_edit'" size=20>";
$output .= "</td><td>";
$output .= "<input id='"test_editing_check'" type='"checkbox'" name='"test_editing_check'" value='"test_editing_check'" '>";
$output .= "</td></tr></table>";

但我的Jquery在原始页面上:

$("#testing_editing").click(function(e){
    if (e.target === this) {
        var testhtml = $(this).html();
        var meatseafood = '<?php echo $meatseafood; ?>';
        $.post('edit_order.php', {'itemtoedit':testhtml,'meatseafood':meatseafood}, function(data) { //make ajax call to check_username.php
        $("#testing_editing").html(data); //dump the data received from PHP page
        });
    }
    });
    $("#test_editing_check").click(function(){
        if ( this.checked ) {
            var testvalue = "HI";
            alert(testvalue);
        }
    });

post()调用返回的复选框似乎不起作用。

为了让主页的jquery代码识别.post()返回,我需要做些什么吗?我希望我的语法没有问题,但我在另一个页面上使用了这个精确的(非常基本的)代码(但没有使用.post()调用),它工作得很好。

基本上,当您单击我的主页编写的div时,它会调用.post()并返回一个可编辑的输入字段和一个复选框。当我点击该复选框时,我希望它再次调用.post()并用新输入的数据更新数据库。

但是,当我选中复选框时,什么也没发生。

jquery似乎无法识别我返回的ajax代码。对于我的测试代码,我所要做的就是在单击复选框时弹出一个警告框,显示它已经"读取"了输入框,现在可以通过.post()调用发送数据进行处理。

如果您需要任何其他代码,请告诉我。它看起来很干燥,所以我不确定为什么它不起作用,这就是我在这里的原因:)

(我想做的是,用户提交表格,在下一页上,会显示一个"确认框",上面写着"这是你想用表格提交的吗?"如果答案是否定的,他们可以"点击"数据并进行更改,而不必重新加载页面。点击部分有效,但复选框会确认"是的,我想将我的数据更改为新输入的数据"不起作用。)

谢谢你的帮助。

Derek Conlon

加载如下复选框后尝试分配事件:

$("#testing_editing").click(function(e){
    if (e.target === this) {
        var testhtml = $(this).html();
        var meatseafood = '<?php echo $meatseafood; ?>';
        $.post('edit_order.php', {'itemtoedit':testhtml,'meatseafood':meatseafood}, function(data) { //make ajax call to check_username.php
           $("#testing_editing").html(data); //dump the data received from PHP page
           // This is applied after loading the data from the ajax call
           $("#test_editing_check").click(function(){
              if ( this.checked ) {
                 var testvalue = "HI";
                 alert(testvalue);
              }
            });
        });
    }
    });