2015-09-06 19 views
1

我是ColdFusion的新手,目前使用的是CFWheels Framework。我有一個片段,它使用jQuery post發送一個帶有兩個參數名稱和時間的視圖的ajax請求。cfwheels查找記錄和輸出爲JSON編碼

$(".building").on("blur", function() { 
     $.post("index.cfm/audit/building", { name: "John", time: "2pm" }) 
      .done(function(data) { 
      alert("Data Loaded: " + data); 
      }); 
     }); 

我的控制器動作

<cffunction name="building"> 
     <cfscript> 
      categories = model("buildings").findByKey(params.name); 

      test = params.name & params.time; 
      renderText(test); 
     </cfscript> 

    </cffunction> 

我的模型

<cfcomponent extends="Model"> 
    <cffunction name="init"> 
     <cfset table("buildings")> 
     <cfset hasMany("rooms")> 
    </cffunction> 
</cfcomponent> 

我希望做一個簡單的任務如下

  1. 檢查是否有建築物過去了名稱中不存在數據庫
  2. 如果這樣的話在PHP返回的行JSON格式,如回聲json_encode
  3. 別人創造新的記錄,並重定向到另一個動作使用參數

我被困在步驟1中,其告訴我

The value for cfqueryparam cannot be determined 

這是什麼意思?請幫助,如果任何人也可以告訴我如何呈現查詢數據的jQuery形式的jQuery文章閱讀。

回答

1

公正地分享答案。

<cffunction name="building"> 
     <cfscript> 
      buidling = model("buildings").findOneByName(params.name); 

      if(IsObject(buidling)) { 

       //return json format 
       renderText(SerializeJSON(buidling));         

      } else { 

       //enter new record 
       new_building = model("buildings").new(); 
       new_building.name = params.name; 
       new_building.save(); 

       //return id json 
       renderText(SerializeJSON(new_building));    
      } 
     </cfscript> 

    </cffunction>