2011-12-07 28 views
1

我得到一個空白的迴應。我甚至硬編碼迴應。我使用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> 
+0

我用硬編碼來查看我是否可以使用createObject組件返回一些東西 –

+1

這個頁面是否託管在同一個域上,即您擁有此代碼的頁面的Url以dev開頭。 lead-hub.com包括http? –

+0

在火蟲中可以看到迴應嗎? – Kishore

回答

2

既然你要在螢火一個空白的反應,但你看你所期望的價值,當你訪問直接在瀏覽器中的URL,它可能會引起我緩存問題。嘗試添加「緩存:假」到你的Ajax設置:

$.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」,看看你是否開始得到回報。

+0

同樣的迴應。 –

+0

請參閱上面的更新 –

+0

謝謝,工作像一個魅力:) –

相關問題