【发布时间】:2016-02-27 06:54:34
【问题描述】:
我想了解coldfusion 到ajax 调用,这样我就可以在不重新加载ma 页面的情况下显示数据。举个简单的例子。通过单击按钮添加两个数字。为此,我需要两个输入元素和一个按钮,它应该显示在同一页面中。我想要做的是当我从用户那里得到输入时,他们点击我需要回答而不重新加载页面。所以我为我的场景使用了组件文件和编写的函数。我通过 ajax 调用我的组件。但我的东西出错了。让我展示一下我做了什么。
冷融合代码
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Adding two numbers</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
<form>
<!--two numbers to add when clicking a button it will show my result in display-->
FIRST NUMBER<input type="text" id="a" name="a" >
SECOND NUMBER<input type="text" id="b" name="b">
<input type="button" name="button" id="button" value="add">
ANS<input type="text" name="display" id="display" readonly>
</form>
</body>
<script language="JavaScript">
$(document).ready(function() {
$("#button").click(function(f) {
// Next, we will be needing the value of the textfield in order to pass it to ColdFusion.
var variableToPass = $("input#a").val();
var variableToPass1 = $("input#b").val();
$.ajax({
url: "add.cfc?method=add&returnformat=json",
data: {
a: variableToPass,
b: variableToPass1
},
success: function(result) {
$("#display").val(result);
}
});
});
});
</script>
</html>
我将它保存为 add.cfm,这是我的组件文件,即(add.cfc)
<cfcomponent>
<cffunction name="add" access="remote" returntype="numeric">
<cfargument name="a">
<cfargument name="b">
<cfset c=a+b>
<cfreturn c>
</cffunction>
</cfcomponent>
在运行我的代码时...我抛出错误类型错误和更多警告...请帮助我
【问题讨论】:
-
将提交按钮 id 更改为单击当前它是“按钮”
-
现在也是同一个 issueeeee....
-
为什么只返回数字数据时有 returnFormat= json?
-
'更多警告'?您收到的错误消息到底是什么?它们是 ColdFusion 错误还是 JS 错误?将它们添加到问题中。
-
请不要描述错误,只需将完整的错误消息添加到your question。
标签: jquery ajax coldfusion