dongping6974 2016-03-23 23:30
浏览 120

jQuery Mobile AJAX不加载页面

echo '<script>
    function ' . $row['idname'] . 'Click(){
        $( "#flip-' . $row['idname'] . '" ).flipswitch( "disable" );
        var isOff = document.getElementById("flip-' . $row['idname'] . '").value;
        if(isOff == "off"){
            console.log("action.php?do=turn-off-' . $row["id"] . '");
            jQuery.ajax({
                url: "action.php?do=turn-off-' . $row["id"] . '",
                type: "GET",
                success:function (data) {
                    $( "#flip-' . $row['idname'] . '" ).flipswitch( "enable" );
                    console.log("SUCCESS!!");
                }
            });
        }else{
            console.log("action.php?do=turn-on-' . $row["id"] . '");
            jQuery.ajax({
                url: "action.php?do=turn-on-' . $row["id"] . ',
                type: "GET",
                success : function (data) {
                    $( "#flip-' . $row['idname'] . '" ).flipswitch( "enable" );
                    console.log("SUCCESS!!");
                }
            });
        }
    }
    </script><br>';

So my problem is that ajax doesn't even load the page that is requested.

It creates this code from the result of a MySQL query, so it's basically a JavaScript file in a PHP File. The target is an empty page that only has some functions.

The function is invoked onChange from this <select>:

echo '<div class="ui-field-contain" style="width: 100%;">
    <label for="flip-' . $row['idname'] . '">' . $row['name'] . '</label> 
    <select onchange="' . $row['idname'] . 'Click()" name="flip-' . $row['idname'] . '" id="flip-' . $row['idname'] . '" data-role="flipswitch">
        <option value="off" selected="">Aus</option> <option value="on">An</option> 
    </select>
 </div>';
  • 写回答

1条回答 默认 最新

  • dongyan1548 2016-03-24 19:49
    关注

    This may solve the problem because it is not a nice way to just replace it with always. You might consider adding some error handling where no wrong elements are tested to be selected with the error message as a part of the id.

    Deprecated jqXHR.success()

    The issue may occur because this method is deprecated since jQuery 1.8. It has been replaced by jqXHR.done().

    jQuery.ajax({
        url: "action.php?do=turn-on-' . $row["id"] . '",
        type: "GET",
        done: function (data) {
            $( "#flip-' . $row['idname'] . '" ).flipswitch( "enable" );
            console.log("SUCCESS!!");
        }
    });
    

    Suggesting another way

    $.get("api.php", {
        do: "turn-on-' . $row["id"] . '"
    }, function (data) {
        console.log(data);}
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记