JS生成的GET变量没有被PHP读取


JS-generated GET variables not being read PHP

我正在使用JavaScript生成表单的action属性:

$("#select-font").on('change', function(){
    var font = $(this).val();
    $("#font-family").val(font);
    $(this).css({
      'font-family': font
    });
    $("#edit-doc").css({
      'font-family': font
    });
    // BUG IS HERE --->
    $('#save')
        .attr('src', '/img/icons2/save.png')
        .attr('onclick', '$(this).parents("form").submit();');
    $('#save')
        .parents('form')
        .attr('action', 
            String($('#save')
                .parents('form')
                .attr('action')) + '&autosave=true');
    });
    $("#select-font-size")
        .on('change', function(){
            var size = $(this).val();
            $("#edit-doc").css({
                'font-size': size
            });
            $("#font-size").val(size);
            // BUG IS HERE --->
            $('#save')
                .attr('src', '/img/icons2/save.png')
                .attr('onclick', 
                    '$(this).parents("form").submit();');
            $('#save')
                .parents('form')
                .attr('action',   
                    String($('#save')
                        .parents('form')
                        .attr('action')) + '&autosave=true');
        });

GET变量被传递到下一页;在URL栏中,位置显示为http://localhost/foo/?var1=a&var2=b&autosave=true。但是,当我测试GET变量时:

if($_GET["autosave"]){
   // some code...
}

条件未运行。为什么PHP看不到变量?

而不是使用

if($_GET["autosave"]){
    // some code...
}

尝试:

if (isset($_GET["autosave"])) {
    // your code...
}

此外,当添加处理程序时,尝试使用jQuery.on(),而不是使用内联点击处理程序

$('#save')
    .attr('src', '/img/icons2/save.png')
    .on('click', function(){
         $(this).parents("form").submit();
    });