【问题标题】:Auto refresh select box when new option added to it添加新选项时自动刷新选择框
【发布时间】:2015-08-27 09:06:53
【问题描述】:

当我在运行时向我的选择框添加数据时,我遇到了一个问题,页面从不自动刷新。我必须手动刷新页面才能让选择选择器填充新添加的选项值。

现在,当我单击选择器中的 ... 虚线按钮时,它会打开一个弹出窗口

如果我在此弹出窗口上添加值,它不会反映在我的选择器中。 请帮我。我要自动刷新选择框

编辑: 我的 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>

我正在使用某种 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);
                }
            }

然后这样称呼它:

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

【问题讨论】:

  • 感谢您详细询问,能否在此处添加代码?
  • @TributetoAPJKalamSir 请查看我添加代码的编辑

标签: javascript jquery ajax drop-down-menu


【解决方案1】:

我猜更新是在服务器上完成的?该 jsp 将被编译成一个 servlet,该 servlet 将呈现一个 HTML 页面,而 HTML 页面又将存在于浏览器中。 HTTP 是一种无状态协议,因此如果没有进一步的请求,jsp 页面将不会知道已经进行了更改。

如果是这种情况,您的选择是:

  • 使用 HTTP/2
  • 使用 WebSockets
  • 使用 Ajax 请求轮询服务器以进行更改

【讨论】:

  • 感谢您的努力。我怎样才能发出 Ajax 请求?
  • 如果您正在使用某种 javascript 框架,它会有一些功能。如果您想成为本地人,请查看developer.mozilla.org/en/docs/Web/API/XMLHttpRequest
  • 请查看我的编辑我已经添加了我的 XMLHttprequest 代码,但它永远不会被执行。
猜你喜欢
  • 2018-03-31
  • 2014-01-06
  • 1970-01-01
  • 2016-06-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-11
  • 2017-05-16
相关资源
最近更新 更多