Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/363.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
Javascript 停留在所选的导航选项卡上,但也要重新加载它以查看更新后更改的数据_Javascript_Php_Laravel - Fatal编程技术网

Javascript 停留在所选的导航选项卡上,但也要重新加载它以查看更新后更改的数据

Javascript 停留在所选的导航选项卡上,但也要重新加载它以查看更新后更改的数据,javascript,php,laravel,Javascript,Php,Laravel,我有一个用于更新从业人员数据的编辑表单,我希望它保持在名为#practices的同一选项卡上(其中有@include practices display和@include practices edit)。要在这两个包含之间交换,我使用editPractitionerButton.js(下面的代码) 我已经制作了一个.js脚本,它可以实现我想要的功能,它保留在#practices选项卡上,但在practices编辑中,不会进入practices显示。此外,更新的数据不可见,只有在手动刷新网站后才可

我有一个用于更新从业人员数据的编辑表单,我希望它保持在名为
#practices
的同一选项卡上(其中有@include practices display和@include practices edit)。要在这两个包含之间交换,我使用
editPractitionerButton.js
(下面的代码)

我已经制作了一个.js脚本,它可以实现我想要的功能,它保留在#practices选项卡上,但在practices编辑中,不会进入practices显示。此外,更新的数据不可见,只有在手动刷新网站后才可见

我的职能:

$(document).ready(function () {
    $('#practitioner_edit_form').on('submit', function(e) {
        e.preventDefault();
        $.ajax({
            url : $(this).attr('action') || window.location.pathname,
            type: "POST",
            data: $(this).serialize(),
            success: function (data) {
                //window.location = $('.nav-tabs a[href="#practitioner"]').tab('show');
                /*^reloads my page to http://rps.me/person/profile/49/[object%20Object] from http://rps.me/person/profile/49/Smith*/
                $('.nav-tabs a[href="#practitioner"]').tab('show');
                /*^stays in the form after submitting, changed data isn't visible, only after reload, but I want to reload to correct nav tab*/
                /*location.reload();*/
            },
            error: function (jXHR, textStatus, errorThrown) {
                alert(errorThrown);
            }
        });
    });
});
控制器功能:

$(document).ready(function () {
    $('#practitioner_edit_form').on('submit', function(e) {
        e.preventDefault();
        $.ajax({
            url : $(this).attr('action') || window.location.pathname,
            type: "POST",
            data: $(this).serialize(),
            success: function (data) {
                //window.location = $('.nav-tabs a[href="#practitioner"]').tab('show');
                /*^reloads my page to http://rps.me/person/profile/49/[object%20Object] from http://rps.me/person/profile/49/Smith*/
                $('.nav-tabs a[href="#practitioner"]').tab('show');
                /*^stays in the form after submitting, changed data isn't visible, only after reload, but I want to reload to correct nav tab*/
                /*location.reload();*/
            },
            error: function (jXHR, textStatus, errorThrown) {
                alert(errorThrown);
            }
        });
    });
});
公共函数更新激活器(请求$Request,$id)
{
$this->validate$请求[
“生效日期”=>“必需”,
]
);
$fields=$request->all();
$specialtyfields=(['effective\u date'=>$request->get('effective\u speciality'),'expiration\u date'=>$request->get('expiration\u speciality'));
$primary_key=$this->PractitionerRepository->getIdName();
$primary\u key\u speciality=$this->PractitionerSpecialtyRepository->getIdName();
$practicer\u speciality\u id=practicerspecialty::where('practicer\u id',$id)->value('practicer\u speciality\u id');
$fields[$primary_key]=$id;
$this->PractitionerRepository->update($fields);
$specialtyfields[$primary\u key\u Speciality]=$Practices\u Speciality\u id;
$this->practicesperspecialtyrepository->update($specialtyfields);
return back()->带有('successUpdate','practices has update!');
}
表单文件(仅按钮):

[…]
保存更改
取消
editPractitionerButton.js

function editPractitionerButton() {
    var editInfoSelector = $('.edit-practitioner');
    var viewInfoSelector = $('.view-practitioner');
    var editBtnSelector =  $('#edit-practitioner-btn');

    editInfoSelector.css('display', 'none');
    editBtnSelector.click(function(){
        if (viewInfoSelector.is(':visible')) {
            viewInfoSelector.css('display', 'none');
            editInfoSelector.css('display', '');
        } else {
            viewInfoSelector.css('display', '');
            editInfoSelector.css('display', 'none');
        }
    });
}

因此,我希望它刷新页面,然后转到“从业者”选项卡。也许我可以在controller函数中使用一个特定的返回来代替js文件?

如果你想使用laravel,而不是javascript,你可以按照下面的方法操作

从选项卡中,您可以传递选项卡名称的隐藏值,并且在控制器中,您可以对其进行会话刷新

session()->flash('active','tab name')

在视图中,您可以检查该值并将其激活

@if(session()->get('active') == 'tab-name') 'active' @endif

如果您想使用laravel,而不是javascript,您可以遵循以下步骤:

从选项卡中,您可以传递选项卡名称的隐藏值,并且在控制器中,您可以对其进行会话刷新

session()->flash('active','tab name')

在视图中,您可以检查该值并将其激活

@if(session()->get('active') == 'tab-name') 'active' @endif
要获取页面重新加载后显示的
#practices
内容,可以使用本地存储,方法如下所示

  • 选项卡链接上附加
    名称
    属性
  • 获取所选选项卡名称并将其保存到本地存储器中
  • 重新加载页面,并根据先前存储的选项卡名称触发所选选项卡
  • 例如,您有如下元素:

    <div id="tabs">
        <ul>
            <li><a href="#practitioner" name="practitioner">Practitioner</a></li>
            <li><a href="#tabs2" name="tabs2">Tab 2</a></li>
            <li><a href="#tabs3" name="tabs3">Tab 3</a></li>
        </ul>
    
    <div id="practitioner">
        <p>practitioner content</p>
    </div>
    
    <div id="tabs2">
        <p>tabs2 content</p>
    </div>
    
    <div id="tabs3">
        <p>tabs3 content</p>
    </div>
    
    $(document).ready(function () {
        $('#practitioner_edit_form').on('submit', function(e) {
            e.preventDefault();
            $.ajax({
                url : $(this).attr('action') || window.location.pathname,
                type: "POST",
                data: $(this).serialize(),
                success: function (data) {
                    //window.location = $('.nav-tabs a[href="#practitioner"]').tab('show');
                    /*^reloads my page to http://rps.me/person/profile/49/[object%20Object] from http://rps.me/person/profile/49/Smith*/
                    // $('.nav-tabs a[href="#practitioner"]').tab('show');
                    /*^stays in the form after submitting, changed data isn't visible, only after reload, but I want to reload to correct nav tab*/
                    /*location.reload();*/
                    var tab = $("#tabs li a.active").attr("name");
                    localStorage.setItem("tab", tab);
                    location.reload();
                },
                error: function (jXHR, textStatus, errorThrown) {
                    alert(errorThrown);
                }
            });
        });
        var currTab = localStorage.getItem("tab");
        if (currTab) {
            $('a[name="' + currTab + '"]').trigger("click");
        }
    });
    
    并将此代码添加到ajax成功响应中,以设置本地存储并触发重新加载页面:

    var tab = $("#tabs li a.active").attr("name");
    localStorage.setItem("tab", tab);
    location.reload();
    
    因此javascript代码如下所示:

    <div id="tabs">
        <ul>
            <li><a href="#practitioner" name="practitioner">Practitioner</a></li>
            <li><a href="#tabs2" name="tabs2">Tab 2</a></li>
            <li><a href="#tabs3" name="tabs3">Tab 3</a></li>
        </ul>
    
    <div id="practitioner">
        <p>practitioner content</p>
    </div>
    
    <div id="tabs2">
        <p>tabs2 content</p>
    </div>
    
    <div id="tabs3">
        <p>tabs3 content</p>
    </div>
    
    $(document).ready(function () {
        $('#practitioner_edit_form').on('submit', function(e) {
            e.preventDefault();
            $.ajax({
                url : $(this).attr('action') || window.location.pathname,
                type: "POST",
                data: $(this).serialize(),
                success: function (data) {
                    //window.location = $('.nav-tabs a[href="#practitioner"]').tab('show');
                    /*^reloads my page to http://rps.me/person/profile/49/[object%20Object] from http://rps.me/person/profile/49/Smith*/
                    // $('.nav-tabs a[href="#practitioner"]').tab('show');
                    /*^stays in the form after submitting, changed data isn't visible, only after reload, but I want to reload to correct nav tab*/
                    /*location.reload();*/
                    var tab = $("#tabs li a.active").attr("name");
                    localStorage.setItem("tab", tab);
                    location.reload();
                },
                error: function (jXHR, textStatus, errorThrown) {
                    alert(errorThrown);
                }
            });
        });
        var currTab = localStorage.getItem("tab");
        if (currTab) {
            $('a[name="' + currTab + '"]').trigger("click");
        }
    });
    
    要获取页面重新加载后显示的
    #practices
    内容,可以使用本地存储,方法如下所示

  • 选项卡链接上附加
    名称
    属性
  • 获取所选选项卡名称并将其保存到本地存储器中
  • 重新加载页面,并根据先前存储的选项卡名称触发所选选项卡
  • 例如,您有如下元素:

    <div id="tabs">
        <ul>
            <li><a href="#practitioner" name="practitioner">Practitioner</a></li>
            <li><a href="#tabs2" name="tabs2">Tab 2</a></li>
            <li><a href="#tabs3" name="tabs3">Tab 3</a></li>
        </ul>
    
    <div id="practitioner">
        <p>practitioner content</p>
    </div>
    
    <div id="tabs2">
        <p>tabs2 content</p>
    </div>
    
    <div id="tabs3">
        <p>tabs3 content</p>
    </div>
    
    $(document).ready(function () {
        $('#practitioner_edit_form').on('submit', function(e) {
            e.preventDefault();
            $.ajax({
                url : $(this).attr('action') || window.location.pathname,
                type: "POST",
                data: $(this).serialize(),
                success: function (data) {
                    //window.location = $('.nav-tabs a[href="#practitioner"]').tab('show');
                    /*^reloads my page to http://rps.me/person/profile/49/[object%20Object] from http://rps.me/person/profile/49/Smith*/
                    // $('.nav-tabs a[href="#practitioner"]').tab('show');
                    /*^stays in the form after submitting, changed data isn't visible, only after reload, but I want to reload to correct nav tab*/
                    /*location.reload();*/
                    var tab = $("#tabs li a.active").attr("name");
                    localStorage.setItem("tab", tab);
                    location.reload();
                },
                error: function (jXHR, textStatus, errorThrown) {
                    alert(errorThrown);
                }
            });
        });
        var currTab = localStorage.getItem("tab");
        if (currTab) {
            $('a[name="' + currTab + '"]').trigger("click");
        }
    });
    
    并将此代码添加到ajax成功响应中,以设置本地存储并触发重新加载页面:

    var tab = $("#tabs li a.active").attr("name");
    localStorage.setItem("tab", tab);
    location.reload();
    
    因此javascript代码如下所示:

    <div id="tabs">
        <ul>
            <li><a href="#practitioner" name="practitioner">Practitioner</a></li>
            <li><a href="#tabs2" name="tabs2">Tab 2</a></li>
            <li><a href="#tabs3" name="tabs3">Tab 3</a></li>
        </ul>
    
    <div id="practitioner">
        <p>practitioner content</p>
    </div>
    
    <div id="tabs2">
        <p>tabs2 content</p>
    </div>
    
    <div id="tabs3">
        <p>tabs3 content</p>
    </div>
    
    $(document).ready(function () {
        $('#practitioner_edit_form').on('submit', function(e) {
            e.preventDefault();
            $.ajax({
                url : $(this).attr('action') || window.location.pathname,
                type: "POST",
                data: $(this).serialize(),
                success: function (data) {
                    //window.location = $('.nav-tabs a[href="#practitioner"]').tab('show');
                    /*^reloads my page to http://rps.me/person/profile/49/[object%20Object] from http://rps.me/person/profile/49/Smith*/
                    // $('.nav-tabs a[href="#practitioner"]').tab('show');
                    /*^stays in the form after submitting, changed data isn't visible, only after reload, but I want to reload to correct nav tab*/
                    /*location.reload();*/
                    var tab = $("#tabs li a.active").attr("name");
                    localStorage.setItem("tab", tab);
                    location.reload();
                },
                error: function (jXHR, textStatus, errorThrown) {
                    alert(errorThrown);
                }
            });
        });
        var currTab = localStorage.getItem("tab");
        if (currTab) {
            $('a[name="' + currTab + '"]').trigger("click");
        }
    });