我使用 ColdFusion 和 jQuery Ajax 没有得到返回数据
我收到的回复是空白的。我什至对响应进行硬编码。我使用 firebug 并复制带有参数的位置,当我将其粘贴到浏览器中时它会显示响应。
代码:
<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>
I am getting a blank response. I even hard code a response. I use firebug and copy the location with parameters and it shows a response when i paste it in my browser.
Code:
<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;
}
}
);
});
}
);
Code For 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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您在 Firebug 中得到空白响应,但是当您直接在浏览器中访问 URL 时您会看到预期的值,因此我认为这可能是缓存问题。尝试将“cache: false”添加到您的ajax设置中:
编辑
因为不是这样 - 我又想到了另一个想法。当您将参数粘贴到 URL 中并直接请求时,您说它对您有用。这意味着您正在使用 GET 请求来请求您的方法,并在 URL 范围内传递参数。这与您的 ajax 请求不同,因为它的类型是:“POST”。尝试将您的 ajax 更改为输入:“GET”,看看您是否开始得到一些回报。
Since you're getting a blank response in firebug, but you see the value you expect when you access the URL directly in the browser, it strikes me as a possible caching issue. Try adding "cache: false" to your ajax setup:
edit
Since that wasn't it - another thought occurred to me. You say it works for you when you paste the parameters in your URL and request it directly. That means you're requesting your method with a GET request, passing the parameters in the URL scope. This is different than your ajax request, since that is type: "POST". Try changing your ajax to type: "GET" and see if you start getting something back.