2013-04-14 33 views
3

我之前使用過這個確切的代碼 - 用PHP作爲處理頁面,但現在在Coldfusion中(不管我使用cfc還是僅僅使用cfm來處理),jQuery不會'噸似乎通過表單對象 - 以及...如果我看着螢火蟲響應,'後'選項卡上顯示所有字段和它們的值..應用程序/ x-www-form-urlencoded但是負責的頁面URL屬性沒有得到它。和(在示例delow中)控制檯日誌(數據)顯示一個空字符串。jquery - 表單數據沒有在ajax調用中傳遞

繼承人我有什麼....

$('#create_client').on('click', function(event) { 

    //form validation 
    var bValid = true; 

    if (bValid) { 
     // AJAX Post data 
     $.ajax({ 
      type: 'POST', 
      dataType: 'html', 
      cache: false, 
      url: '/cfc/clent.cfc?method=put', 
      data: $('#client-form').serialize(), 
      success: function(data){ 
       console.log(data); 
       loadClientTable(); 
      }, 
      error: function(){ 
       // tell user there was a problem 
       $('#clients-message').html('<p>There was a problem submitting your request... Doh!</p>'); 
      } 
     }); 
    } 

} 

和這裏的形式

<form name="client-form" id="client-form" class="singleLineForm" > 
<label for="firstname">First Name: </label> 
<input type="text" name="firstname" id="firstname" value="" maxlength="15" class="text ui-widget-content ui-corner-all" /> 
<label for="lastname">Last Name: </label> 
<input type="text" name="lastname" id="lastname" value="" maxlength="15" class="text ui-widget-content ui-corner-all" /> 
<label for="email">Email: </label> 
<input type="text" name="email" id="email" value="" maxlength="50" class="text ui-widget-content ui-corner-all" /> 
<label for="password">Password: </label> 
<input type="text" name="password" id="password" value="" maxlength="20" class="text ui-widget-content ui-corner-all" /> 
<label for="isActive">Active? </label> 
<input type="checkbox" name="isActive" id="isActive" value="1" class="checkbox ui-widget-content ui-corner-all" /> 
<input type="button" name="create_client" id="create_client" value="Create Client" class="button ui-widget-content ui-corner-all" /> 
</form> 

認沽在CFC看起來是這樣的(現在)

<cffunction name="put" access="public" returntype="structure" hint="PUT method, handles data transfering." > 
    <cfargument name="email" type="string" required="yes" > 
    <cfargument name="password" type="string" required="yes" > 
    <cfargument name="firstname" type="string" required="yes" > 
    <cfargument name="lastname" type="string" required="yes" > 
    <cfargument name="isActive" type="numeric" required="yes" > 

    <cfset _return = '' /> 

    <cfquery name="insertClient" datasource="#application.DSNwrite#" > 
     INSERT INTO clients 
     ( 
      email 
      ,password 
      ,firstname 
      ,lastname 
      ,isActive 
     ) 
     VALUES 
     ( 
      <cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(arguments.email)#" /> 
      ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(arguments.password)#" /> 
      ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(arguments.firstname)#" /> 
      ,<cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(arguments.lastname)#" /> 
      ,<cfqueryparam cfsqltype="cf_sql_bit" value="#val(arguments.isActive)#" /> 
     ) 
    </cfquery> 

    <cfreturn _return /> 
</cffunction> 
+0

你能告訴我們在client.put()中的代碼嗎? –

+0

@scott - 那裏你去... – jpmyob

+0

也許嘗試改變POST到PUT? – 1337holiday

回答

5

你CFC方法返回一個空字符串。

你有這樣的:

<cfset _return = '' /> 

,並在方法結束時,你有這樣的:

<cfreturn _return /> 

但是,你永遠不會設置_return爲不同的值。要測試是這樣的問題,請試試這個:

<cfset _return = 'moo' /> 

如果你得到'moo'返回,一切都按預期工作。

0

你可以像下面那樣通過ajax調用表單數據。

var formData = $('#client-form').serialize(); 
$.ajax({ 
    url: '/cfc/clent.cfc?method=put&' + formData, 
    type: 'POST', 
    data:{ 
    }, 
    success: function(data){}, 
    error: function(data){}, 
}) 
相關問題