简体   繁体   English

添加新选项时自动刷新选择框

[英]Auto refresh select box when new option added to it

I am facing a problem when I add data to my select box at run time the page never auto refreshes. 当我在运行时将数据添加到选择框时,页面无法自动刷新时遇到了问题。 I have to manually refresh the page in order to get select picker populated with newly added option value. 我必须手动刷新页面,才能用新添加的选项值填充选择器。

在此处输入图片说明

Now when I click ... dotted button in select picker it opens a popup 现在,当我单击“选择器”中的“ ...”虚线按钮时,将打开一个弹出窗口

在此处输入图片说明

If i add value on this popup it does not gets reflected in my selectpicker. 如果我在此弹出窗口中添加值,则不会反映在我的选择器中。 Please help me. 请帮我。 I want to auto refresh select box 我想自动刷新选择框

EDIT: MY JSP CODE: 编辑:我的JSP代码:

<TD ALIGN="LEFT">
    <fdms:speedselect name="firstCallInformation" property="placeDeath" category="LOCDEATH" column="1"
            combo="true" maxlength="50" size="1" textsize="30">
    <fdms:linkoption text="Edit list..." script="tableWindow2('LOCDEATH',1,'firstCallInformation.placeDeath')" />
    <fdms:targetfield column="2" property="locationDeceased" />
    <fdms:targetfield column="3" property="placeDeathCity" />
    <fdms:targetfield column="6" property="placeDeathState" />
    <fdms:targetfield column="7" property="placeDeathZip" />
    <fdms:targetfield column="8" property="locDeathLicenseNumber" />
    </fdms:speedselect>
</TD>

I am using sort of ajax call but not sure is it correct or not 我正在使用某种ajax调用,但不确定是否正确

function loadFacility(callback)
            {
                alert('In loadFacility');
                var xmlhttp;
                var keys=document.firstCallInformation.facilityselect.value;
                var urls="localhost:8080/webfdms/showFirstCallInformation.do?vitalsId=366";
                if (window.XMLHttpRequest)
                {// code for IE7+, Firefox, Chrome, Opera, Safari
                    xmlhttp=new XMLHttpRequest();
                }
                else
                {// code for IE6, IE5
                    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
                xmlhttp.onreadystatechange=function()
                {
                    if (xmlhttp.readyState==4 && xmlhttp.status == 200)
                    {
                         //var some=xmlhttp.responseXML.documentElement;
                        var resposne = xmlhttp.responseText;
                        alert(resposne);
                        callback(xmlhttp.responseText);
                    }
                }
                xmlhttp.open("GET",urls,true);
                xmlhttp.send(null);
            }
            function loadFacilityCallback(resposne){
                if(resposne != null){
                    alert(resposne);
                }
            }

And calling it like : 并像这样调用它:

<fdms:speedselect property="facility" category="FacilityPlace" maxlength="50" column="1" combo="true" size="1" textsize="60" onchange="loadFacility(callback)">

I'm guessing the update is done on the server? 我猜测更新已在服务器上完成? The jsp will be compiled into a servlet that will render a HTML page, which in turn will live on the browser. 该jsp将被编译到一个servlet中,该servlet将呈现HTML页面,而该页面又将存在于浏览器中。 HTTP is a stateless protocol, so without a further request the jsp page will not know that the change has been made. HTTP是无状态协议,因此,在没有其他请求的情况下,jsp页面将不会知道已进行更改。

If this is the case your options are: 如果是这种情况,您可以选择:

  • Use HTTP/2 使用HTTP / 2
  • Use WebSockets 使用WebSockets
  • Poll the server using Ajax request for changes 使用Ajax请求更改来轮询服务器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM