AJAX amp; Coldfusion: Performing an update to database and reflecting changes without reload(阿贾克斯和Coldfusion:对数据库执行更新并反映更改而无需重新加载)
问题描述
我在可视化此处需要的解决方案时遇到问题.我正在处理的网站上有一个选择菜单,客户希望能够选择一个名为创建新源"的选项,然后会弹出一个带有空白字段的 JS 窗口供用户使用输入新的来源.
I'm having problems visualizing the solution that I need here. I have a select menu on the site that I'm working on and the client would like to be able to select an option called "Create New Origin", which would then have a JS window pop up with a blank field for the user to type in that new origin.
提交此表单后,数据库将更新,选择菜单现在将显示此项目,而无需整个页面刷新.
Upon submitting this form the database would be updated and the select menu would now feature this item without an entire refresh of the page.
数据库方面的一切都已设置好并准备就绪,Coldfusion 的 99% 也是如此.
The database side of things is all set up and ready to go, as is 99% of the Coldfusion.
以下是相关表单字段的片段:
Here's a snippet of the form field in question:
<p class="_30NP" align="right">
<label>Origin </label>
</p>
<p class="_20NP">
<cfselect
name="Origin"
id="Origin"
query="Origin"
display="description"
value="code"
required="yes">
<option value="new">New Origin</option>
</cfselect>
</p>
这是 CFQUERY:
Here's the CFQUERY:
<CFQUERY DBTYPE="Query" NAME="Origin">
SELECT Code, [Description]
FROM ZCODES WHERE CODE = 0
UNION ALL
SELECT Code, [Description]
FROM ZCODES
WHERE FieldName = 'Origin'
ORDER BY 1
</CFQUERY>
这是一个非常简单的问题,答案可能非常简单,我只是很少接触 AJAX.
This is a very simple question with probably a very simple answer, I just have little exposure to AJAX.
如何在不完全刷新页面的情况下提交表单(弹出窗口)并刷新选择列表?
How do I submit a form (pop up window) and refresh the select list without completely refreshing the page?
推荐答案
我会使用像 jQuery 这样的 javascript 库来处理你的 ajax.
I would use a javascript library like jQuery to handle your ajax.
单击按钮后,使用 $.get(), $.post() 或 $.ajax() 与服务器通信.每个人都会做出回应.响应类型由您决定.您可以返回 JSON 并将其解析出来,也可以直接返回 HTML.我可能会简单地返回 html 以快速简便.
Once the button is clicked use $.get(), $.post(), or $.ajax() to communicate with the server. Each will provide a response. The response type is up to you. You could return JSON and parse it out, or you could return straight HTML. I might simply return html to be quick and easy.
<cfoutput query = "...">
<option value = "...">...</option>
</cfoutput>
获得结果后,使用 $.html() 更新 select's
选项.
Once you have the result, use $.html() to update the select's
options.
这篇关于阿贾克斯和Coldfusion:对数据库执行更新并反映更改而无需重新加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:阿贾克斯和Coldfusion:对数据库执行更新并反映更改


- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- addEventListener 在 IE 11 中不起作用 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07