The following code works. What I’d like to do is change it from accepting a single value to accepting an array of objects, such that instead of posting 1,”Item One”, I’m looping through the object and posting 1,”Item One”, 2,”Item Two”, etc.
!function($, window, undefined) {
var local = {};
local.data = {};
local.type= 'post',
local.dataType= 'json',
local.data.method = 'Save',
local.data.ItemNo = 1;
local.data.ItemName = 'Item One';
var myPromise = $.ajax('Upload.cfc',local);
myPromise.done(function(result) {
console.log('success!');
});
myPromise.fail(function(A,B,C) {
$('body').append(A.responseText);
console.log(B);
console.log(C);
});
}(jQuery, window);
And
<cfcomponent>
<cffunction name="Save" access="remote">
<cfargument name="ItemNo">
<cfargument name="ItemName">
<cfset var local = {}>
<cfquery datasource="#Application.Datasource#" username="#Application.Username#" password="#Application.Password#">
INSERT INTO lru.Item(ItemNo,ItemName) VALUES
(<cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.ItemNo#">
,<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.ItemName#" maxlength="10">
)
</cfquery>
</cffunction>
</cfcomponent>
index.cfm:
add.cfc:
This example should get you going, just pass an array from javascript to ColdFusion, then loop that array in your cfc.