为什么在AJAX发布之后,在这种情况下,URL重定向到带有POST参数(例如GET参数)的URL?

时间:2019-12-23 16:19:37

标签: javascript php jquery

addonmodule Controller.php中:

我附加了此order_detail函数:

    /**
     * @param $vars
     */
    public function order_detail($vars){

        $modulelink = $vars['modulelink']; // eg. addonmodules.php?module=addonmodule
        $version = $vars['version']; // eg. 1.0
        $LANG = $vars['_lang']; // an array of the currently loaded language variables

        $orderid = 28;//isset($_REQUEST['orderid']) ? $_REQUEST['orderid'] : '';

        $sql = "SELECT tblhosting.id, tblhosting.regdate, tblhosting.domain, tblhosting.billingcycle, tblhosting.nextduedate, tblhosting.nextinvoicedate, tblhosting.termination_date, tblhosting.domainstatus, tblhosting.username, tblhosting.notes, tblhosting.dedicatedip, tblhosting.assignedips FROM tblhosting ";
//        $sql .= "LEFT JOIN tblorders ON ";
//        $sql .= "tblhosting.orderid = tblorders.id ";
        $sql .= ("WHERE tblhosting.orderid = " . $orderid);

        $tblhostings = Capsule::select($sql);

        $table_tbody = "";
        for($i = 0; $i < count($tblhostings); $i ++) {

            $item = $tblhostings[$i];

            $row = "<tr>";

            $row .= ("<td><input type='text' id='tblhosting-id' name='id' class='form-control' readonly=\"readonly\" style='width:80px;' value='" . $item->id . "'></td>");
            $row .= ("<td><textarea id='tblhosting-domain' name='domain' class='form-control' style='width:320px;'>" . $item->domain . "</textarea></td>");
            //$row .= ("<td>" . $item->billingcycle . "</td>");
            $row .= ("<td ><div style='width:80px;'>" . $item->nextduedate . "</div></td>");
            $row .= ("<td ><div style='width:80px;'>" . $item->nextinvoicedate . "</div></td>");
            //$row .= ("<td>" . $item->termination_date . "</td>");
            //$row .= ("<td>" . $item->username . "</td>");

            $row .= ("<td><textarea id='tblhosting-dedicatedip' name='dedicatedip' class='form-control' style='width:200px;'>" . $item->dedicatedip . "</textarea></td>");
            $row .= ("<td><textarea id='tblhosting-assignedips' name='assignedips' class='form-control' style='width:200px;'>" . $item->assignedips .  "</textarea></td>");
            $row .= ("<td>" . $item->domainstatus . "</td>");
            $row .= ("<td><div style='width:80px;'>" . $item->regdate . "</div></td>");
            $row .= ("<td><textarea id='tblhosting-notes' type='textarea' name='notes' class='form-control' style='width:200px;'>" . $item->notes .  "</textarea></td>");

            $row .= ("<td> <button id='modify' type='submit' class='btn btn-warning'>modify</button>  <button id='send-email' type='button' class='btn btn-success'>Send email</button>  </td>");

            $row .= "</tr>";

            $table_tbody .= $row;

        }


        $div = "<div class='container'><div><h2>order ID: {$orderid} :</h2></div>";

        $div .= "<div >";

        $div .= "<form '><table class='table'>";

        $div .= "<thead><tr>";

        $div .= "<th>product ID</th>";
        $div .= "<th>product name</th>";
        //$div .= "<th>billingtype</th>";
        $div .= "<th>nextdue</th>";
        $div .= "<th>nextvoice</th>";
        //$div .= "<th>terminate time</th>";
        //$div .= "<th>username</th>";

        $div .= "<th>dedicated IP</th>";
        $div .= "<th>assigned IP</th>";
        $div .= "<th>status</th>";
        $div .= "<th>regdate</th>";
        $div .= "<th>note</th>";
        $div .= "<th>ope</th>";

        $div .= "</tr></thead>";

        $div .= "<tbody>";
        $div .= $table_tbody;
        $div .= "</tbody>";

        $div .= "</table>";

        $div .= "</div></div>";

        $js = "<script>";
        $js .= "

            var origin_url = window.location.href;//\"http://192.168.33.10/whmcs-nlidc.com/whmcs/admin/addonmodules.php?module=addonmodule&action=order_detail&orderid=100\";
            var url_array =origin_url.split(\"/admin/\")
            var url = url_array[0] + \"/admin/api/admin_apis.php\";



            jQuery(document).ready(function(){
                $('#modify').click(function(){
                    //alert('modify');

                    var id = $('#tblhosting-id').val();
                    var domain = $('#tblhosting-domain').val();
                    var dedicatedip = $('#tblhosting-dedicatedip').val();
                    var assignedips = $('#tblhosting-assignedips').val();
                    var notes = $('#tblhosting-notes').val();

                    var params = {
                        admin_api:'update_tblhosting_support',
                        id: id,
                        domain: domain,
                        dedicatedip: dedicatedip,
                        assignedips: assignedips,
                        notes: notes,

                    }

                    $.post(url, params,function(data,status){
                        //alert(\"Data: \" + data + \"nStatus: \" + status);

                        var data_obj = JSON.parse(data);

                        if (status == 'url' && data_obj.status == 200) {
                            alert('update success');

                            alert(window.location.href(www.baidu.com);)
                        }else {
                            //alert('update fail');
                        }
                    });

                })
            });

            jQuery(document).ready(function(){
                $('#send-email').click(function(){
                    alert('send email');
                })
            });

        ";
        $js .= "</script>";


        $html = $div . $js;
        return <<<EOF
            $html
EOF;


    }
}

enter image description here

我想使用这种方式来更新tblhosting条目。您会看到我的jQuery代码想要使用post方法来更新tblhosting条目。

当我单击更新按钮时,它将执行更新URL,但是它将重定向到该URL

http://192.168.33.10/whmcs/admin/addonmodules.php?id=28&domain=10.93.240.193-194(15M%29+HK-Z7-A15++E5-2650%282CPU%29%2F32G%2F500G+ssd%2F++&dedicatedip=10.93.240.193-194&assignedips=10.93.240.193%0D%0A10.93.240.194&notes=02442%2F66655%0D%0A10&intellisearch=1&token=ac271aed87528e68969608329e8a1f4d2a35c858&value=

enter image description here


我们知道,ajax不会刷新整个页面,并且默认情况下不会在请求后重定向,为什么会有所不同?

谁知道避免重定向的方法?


我也尝试使用

window.location.href(origin_url);

在错误的重定向后重定向回原位,但不会执行。

0 个答案:

没有答案