我得到没有返回数据使用ColdFusion和jQuery Ajax [英] I am getting no return data using ColdFusion and jQuery Ajax

查看:176
本文介绍了我得到没有返回数据使用ColdFusion和jQuery Ajax的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到一个空白回复。我甚至硬编码一个响应。我使用firebug并复制参数的位置,它显示一个响应,当我粘贴在我的浏览器。

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.

代码:

<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;
                    }
                }
            );
        });
    }
);

p>

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>


推荐答案

因为你在firebug中得到一个空白的响应,但是当您直接在浏览器中访问URL时,您会看到所期望的值,它会作为一个可能的缓存问题触发我。尝试在您的ajax设置中添加cache:false:

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:

$.ajax({
    cache: false,
    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;
    }
});

编辑

因为那不是它 - 另一个想法发生在我。您可以说,当您在网址中粘贴参数并直接请求时,它适用于您。这意味着您正在使用GET请求请求您的方法,并传递URL范围中的参数。这与您的ajax请求不同,因为它是类型:POST。尝试改变你的ajax键入:GET,看看你是否回来了。

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.

这篇关于我得到没有返回数据使用ColdFusion和jQuery Ajax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆