如何在不使用 jquery 刷新页面的情况下保持在同一 jsp 页面实例上

How to stay on the same instance of jsp page without refreshing the page using jquery

本文关键字:jsp 实例 情况下 jquery 刷新      更新时间:2023-09-26

我有如下提交按钮:

<form:form commandName="DRCNdetails"  id="frm1" method="POST" action="addNewDelayReason.do" >
</form:form>
    <button class="btnStyle blueBtn" id = "subBtn" onclick="showBox()"> 
                    <span class="left"> 
                        <span class="right">Submit</span> 
                    </span> 
                </button>
                $("#subBtn").click(function()
        {
        //if($("#reasonValue").val(missedReasonValue)!="")
            var missedReasonValue =$("#mrclist").val();
            var delayReasonValue=$("#text1").val();
            var preFixValue=$("#text2").val();
            alert("missedReasonValue :: "+missedReasonValue);
            $("#reasonValue").val(missedReasonValue); 

            document.getElementById("frm1").submit();

        showLtBox('mask', 'confirmationMsg');
                fadeOutLtBox('asgnExistMisdReasonCode');
        });

               function showBox(){
            alert('hi in showlightbox');
             showLtBox('mask', 'confirmationMsg');
             fadeOutLtBox('asgnExistMisdReasonCode');
              }

单击提交按钮后,相应的数据将保存在数据库中,但我无法显示弹出屏幕showLtBox('mask', 'confirmationMsg');。它会出现几秒钟,名为div confirmationMsg 的弹出窗口阻止程序永远不会出现在屏幕上。

它令人耳目一新,因为您没有使用 ajax 提交表单。

$('#frm1').on('submit',function(e){
    e.preventDefault()
    var url = $(this).attr('action')
    var formData = $(this).serialize()
    //Submit the request via Ajax
    $.post( url, data, function( data ) {
        //Show the alert box you want to show
        showLtBox('mask', 'confirmationMsg');    //or th showBox() you defined
    });
})