jquery - Sending all of form scope to a CFC asynchronously -
jquery - Sending all of form scope to a CFC asynchronously -
currently working on trying figure out asynchronous submission in coldfusion. have problem this. have form want submit remote chlorofluorocarbon , sort of response back. (eventually form going have draft function...) know how set each part: form , cfc. problem connecting them!!! there similar post this, none offer sufficient information....for me @ least.
form:
<cfform action = "/cfc/request.cfc?method=updaterequest" method = "post" name = "requestform" id = "requestform" enctype="multipart/form-data"> ........<!-- fields redacted --> </cfform>
cfc method (this test):
<cffunction name="updaterequest" access="remote" returntype="numeric"> <cfargument name="form" type="struct" required="yes"> <cfset var status = 0> <cfreturn status> </cffunction>
note: chlorofluorocarbon function set remote etc. etc. etc...
i have form here should post cfc, goes chlorofluorocarbon page. don't want this. i've grown frustrated trying utilize ajax coldfusion. i'm ready resort using jquery submit it. can jquery...however don't know how fields struct. (this form going large...) i'd see how send form info struct in either coldfusion or jquery. want able retain form field names.
even if point me in right direction...that great. i've tried find tutorial on sometime , have not been able too.
if want pass form controls structure, first seek serializing form elements json string, pass string webservice. webservice, utilize deserializejson() convert structure. here's code should close this:
<script> /* function prototype code modified here: http://api.jquery.com/serializearray/#comment-130159436 */ (function( $ ){ $.fn.serializejson=function() { var json = []; jquery.map($(this).serializearray(), function(n, i){ json.push('"' + escape(n['name']) + '":"' + escape(n['value']) + '"'); }); homecoming '{' + json.join(',') + '}'; }; })( jquery ); // create request webservice $.post('mycomponent.cfc?method=updaterequest', { formjson: $("#requestform").serializejson()}, function () { /* handle response here. */ }) </script>
then in cfc, alter argument so:
<cffunction name="updaterequest" access="remote" returntype="numeric"> <cfargument name="formjson" type="string" required="yes"> <cfset var formstruct = deserializejson(arguments.formjson)> <cfset var status = 0> <cfreturn status> </cffunction>
jquery ajax asynchronous coldfusion cfc
Comments
Post a Comment