AJAX下拉框(HTML选择)在Chrome下拉框、AJAX、Chrome、HTML

2023-09-10 18:32:44 作者:仰望↘同一片星空‖

我有以下选择选项codeS:

I have the following select option codes:

           <select name="startTime" id = "startTime" onchange = "javascript:timeChange();">

                    <c:choose>
                            <c:when test="${param.cid != null}">
                                    <option value="<c:out value="${timevalue}"/>" selected><c:out value="${time}" /></option>
                                    <option value="<c:out value="-"/>"><c:out value="Choose time"/></option>
                            </c:when>
                            <c:otherwise>
                                    <option value="<c:out value="-"/>" selected><c:out value="Choose time" /></option>
                            </c:otherwise>
                    </c:choose>
                    <option value="10:00:00" >10:00</option>
                    <option value="11:00:00" >11:00</option>
                    <option value="12:00:00" >12:00</option>
                    <option value="13:00:00" >13:00</option>
                    <option value="14:00:00" >14:00</option>
                    <option value="15:00:00" >15:00</option>
                    <option value="16:00:00" >16:00</option>
                    <option value="17:00:00" >17:00</option>
                    <option value="18:00:00" >18:00</option>
                    <option value="19:00:00" >19:00</option>
                    <option value="20:00:00" >20:00</option>
                    <option value="21:00:00" >21:00</option>
               </select>

和还具有以下的ajax code:

and also have the following ajax code:

            $.ajax({
            url: "temporary_checking.jsp",
            type: "POST",
            data: data,
            async: true,
            timeout:6000,
            dataType: "html",
            success: function (data) {
                    data = data.trim();
                    var n = data.indexOf("ERROR",0);
                    if( n > -1 ){
                            if(data.indexOf("ERROR 2",0) >= 0 ){
                                    alert("Error to allocate time slot");
                                    return true;
                            }
                    }else{
                            window.location.reload(false);
                            if(getCookie('Times') != null || getCookie('Times') != undefined)
                            {
                                    deleteCookie('Times');
                            }
                            setCookie('reload',1,'');
                            setCookie('zerosecond',1,'');
                    }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
                    document.getElementById('startTime').value = "-";
                    alert("Error to book time slot : " + textStatus + '\n ' + errorThrown);
                    return false; 
            }
        });

那么,问题是,每当它选择一个选项,如17:00则该值将恢复为默认是选择时间选项。它在FireFox上没有问题,但是。任何解决办法?在此先感谢

So, the problem is whenever it selects an option e.g 17:00 then the value will be back to default which is "Choose time" option. It has no problem on FireFox, however. Any solution? Thanks in advance

推荐答案

如果你是调用函数window.location.reload(假);该页面将立即重新加载,所有的JS状态将丢失,也不会执行该语句之后的code线。所以,最好是设置cookie重装之前:

If you are call the function "window.location.reload(false);" the page will immediately reloaded, all JS states will be lost and the code lines after this statement will not be executed. So it's better to set the cookie before the reload:

...

} else {
    if (getCookie('Times') != null || getCookie('Times') != undefined) {
        deleteCookie('Times');
    }
    setCookie('reload',1,'');
    setCookie('zerosecond',1,'');
    window.location.reload();
}
...

误参数是没有意义对我来说,因为它是默认值: http://www.w3schools.com/jsref/met_loc_reload.asp

The "false" parameter makes no sense for me, because it is the default value: http://www.w3schools.com/jsref/met_loc_reload.asp