CF/jQuery添加到数据库并刷新到Select

CF/jQuery添加到数据库并刷新到Select,jquery,coldfusion,Jquery,Coldfusion,我正在使用ColdFusion和jQuery制作一个单页应用程序。我正试图找出如何添加一个新的经销商与我的新按钮,打开一个模式,要求新的经销商名称。。一旦接受,我想用下一个可用的ID更新数据库,添加经销商,然后以某种方式将名称刷新显示在经销商下拉列表中。目前,我有一个经销商下拉列表,它从一个称为cfc的数据库中填充,如下所示: index.cfm <cfset cfcDealerTracking = new dealerTracking()> <cfset de

我正在使用ColdFusion和jQuery制作一个单页应用程序。我正试图找出如何添加一个新的经销商与我的新按钮,打开一个模式,要求新的经销商名称。。一旦接受,我想用下一个可用的ID更新数据库,添加经销商,然后以某种方式将名称刷新显示在经销商下拉列表中。目前,我有一个经销商下拉列表,它从一个称为cfc的数据库中填充,如下所示:

index.cfm

    <cfset cfcDealerTracking = new dealerTracking()>
    <cfset dealerListing = cfcDealerTracking.allDealers()>

<div class="col-xs-12">
   <label for="Dealers"></label>
   <div class="input-group">
     <select name="Dealers" id="Dealers" class="form-control">
          <option value="" selected></option>
        <cfoutput query="dealerListing">
          <option value="#Name#">#Name#</option>
        </cfoutput>
    </select> <span class="input-group-btn">
   <button type="button" class="btn btn-default" data-toggle="modal" data-target="#NewDealer"><u>N</u>EW</button>
                            </span>

     </div>
</div>    
dealerTracking.cfc

<cfcomponent>

<cffunction name="allDealers" access="public" returntype="query">
    <cfset var getDealers = ''>
    <cfquery name="getDealers">
        SELECT Name
        FROM dbo.Dealer_Track_Dealers
        ORDER BY Name
    </cfquery>
    <cfreturn getDealers>
</cffunction>

</cfcomponent>
我所尝试的:

在下的index.cfm中添加了行

cfc新增功能:

<cffunction name="insertAddedDealer" access="public" returntype="boolean">
    <cfset var newDealerAdd = ''>
    <cfquery name="newDealerAdd">
        INSERT INTO dbo.Dealer_Track_Dealers (Name)
        VALUES (#form.NewDealerName#)
    </cfquery>
  <cfreturn true>
</cffunction>
AJAX调用以设置变量NewDealerSession.cfm:

<cfset session.dealerwork.newdealername = form.NewDealerName >
    <cfoutput>#SerializeJSON(session.dealerwork.newdealername)#</Cfoutput>

向模式中添加一个onClose函数,该函数调用主页窗口中的更新函数。top.updatedropdown函数刷新ajax调用中的下拉列表。

大约8年前,我做了类似的事情。我使用了3个文件,分别称为Page1.cfm、page2.cfm和Page3.cfm

Page1.cfm具有主窗体,用户可以动态添加记录。它包括以下javascript代码:

function ServiceOther() {
if (document.someForm.someSelect.value == "OTHER" ) {

NewContact=window.showModalDialog("Page2.cfm?someUrlVariables, etc");

if (NewContact == true) // return value from dialogue
window.location="Page1.cfm?urlvariables";

} // end if
}// end of function
Page2.cfm包括以下内容:

<cfform name="someForm" 
Action="Page3.cfm" 
method="post" 
onsubmit="window.returnValue = true; window.close();">
Page3.cfm有代码来处理Page2.cfm中的表单,添加记录,还有:

<script language=javascript>
function CloseWindow() {
window.open('','_self','');
window.opener = top;
window.close();
}
</script>
最后

<body onload="window.returnValue = true;  CloseWindow();">
</body>
</html>

可能有更好的方法可用,但这是有效的。

模态将发布到index.cfm?如果是,并且希望新值出现在列表中,则添加的行应位于列出值的行之前。你的问题有点让人困惑,因为它是一个单页应用程序,所以当你打开时,新按钮旁边的下拉列表已经填充了。我希望单击“新建”按钮打开模式,然后输入新的经销商名称。当选择accept时,它将提交到数据库,然后刷新index.cfm页面,这样它就会出现在NewButton旁边的下拉列表中。有没有机会举个例子,我对这种Ajax技术非常陌生
<body onload="window.returnValue = true;  CloseWindow();">
</body>
</html>