我有一个使用getJSON访问同一域中的cfc的页面。一切工作正常在开发服务器上,但不是在现场。其他jquery执行得很好,只是不是.getJSON调用。我也尝试过来自网络的几个例子,并使用Ajax代替getJSON,但结果总是相同的 - 测试精确,而不是实况。jquery getJSON调用cfc在测试服务器上工作,但不生活
这是我目前用来测试的代码,它是http://www.christopherchin.com/blog/index.cfm/2010/3/25/HELP-CFCjqueryJSON示例的简化版本。
index.cfm:
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
chkUsernameUnique = function(theUsername){
$.getJSON("/jsonTest/mycfc.cfc", {
method: 'chkUsername',
Username: theUsername,
returnformat: 'json'
}, function(isUsernameUnique){
$("#theErrorDivID").html(isUsernameUnique);
});
};
</script>
<input type="text" name="username" id="username" onchange="chkUsernameUnique(this.value);" />
<div id="theErrorDivID"></div>
mycfc.cfc:
<cfcomponent>
<cffunction name="chkUsername" access="remote" returnformat="json" output="false">
<cfargument name="Username" required="true">
<cfset thisRecordCount=4>
<cfreturn thisRecordCount>
</cffunction>
</cfcomponent>
忽略一个事实,即它不会做任何有用的事情,这是纯粹的供测试用。在测试服务器上,它会做它应该做的事情,如果我在框中键入内容,则显示4。在肝脏服务器上,它实际上并没有发生错误,浏览器显示javascript正在验证,但没有任何反应。在这一点上,我认为它可能是服务器或ColdFusion管理中的一个设置,而不是与代码有关的任何事情,但我甚至不知道从哪里开始。任何帮助将非常感激。
更新:我现在看到在萤火虫在测试服务器上的响应是4.0,但在实时服务器上它是//4.0。额外的斜杠是什么意思?
哪些浏览器你试过这个?也有你检查与提琴手的请求,看看有什么回应? –
尝试在浏览器上粘贴url目录,看看究竟返回什么作为回应 http:// [yourdomain] /jsonTest/mycfc.cfc?method=chkUsername&username= [用户名]&returnformat = json –