我有一個使用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 –