我得到一個空白的迴應。我甚至硬編碼迴應。我使用firebug並用參數複製位置,當我將它粘貼到瀏覽器中時顯示響應。我得到沒有返回數據使用ColdFusion和jQuery Ajax
代碼:
<script type="text/javascript">
$(document).ready(function(){
$("#mySubmitButton").click(function(){
var zipCodeFilter = $('input[name=zipCodeFilter]').val();
var zipRadius = $('select[name=zipRadius]').val();
var querystring = "zipCodeFilter="+zipCodeFilter+"&zipRadius="+zipRadius;
$.ajax(
{
type: "POST",
dataType: "json",
url: "http://dev.lead-hub.com/datasource/dataAccess.cfc?method=getZipCodes&returnformat=json",
data: querystring,
success: function(response){
var resp = jQuery.trim(response);//getting alot of whitespace in my return CFC method
alert(resp);
return false;
if (resp == 'true'){
$('#loginResponse').html("<span style='color: green;font-weight: bold; font-size: 15px;'>Success!!</span>");
// you'll want to put your code here to move onto the next page. I would simply do a page refresh
// and continue with using the session's login data
}else{
$('#loginResponse').html("<span style='color: red;font-weight: bold; font-size: 15px;'>Failed!!</span>");
}
return false;
}
}
);
});
}
);
代碼爲CFC:
<cffunction name="getZipCodes" access="remote" returnType="string">
<cfargument name="zipCodeFilter" required="true" type="numeric">
<cfargument name="zipRadius" required="true" type="numeric">
<cfset var local = {} />
<cfset local.getZipCodes = "" />
<cfquery name="local.getZipCodes" dataSource="#application.dns_live#">
SELECT h.*
FROM tbl_zipcodes g
JOIN tbl_zipcodes h ON g.zipcode <> h.zipcode
AND g.zipcode = '#arguments.zipCodeFilter#'
AND h.zipcode <> '#arguments.zipCodeFilter#'
WHERE g.GeogCol1.STDistance(h.GeogCol1)<=(#arguments.zipRadius# * 1609.344)
</cfquery>
<cfset local.returnString = "Good" />
<cfreturn local.returnString />
</cffunction>
我用硬編碼來查看我是否可以使用createObject組件返回一些東西 –
這個頁面是否託管在同一個域上,即您擁有此代碼的頁面的Url以dev開頭。 lead-hub.com包括http? –
在火蟲中可以看到迴應嗎? – Kishore