Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7886389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:18:22+00:00 2026-06-03T05:18:22+00:00

The following code works. What I’d like to do is change it from accepting

  • 0

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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:18:23+00:00Added an answer on June 3, 2026 at 5:18 am

    index.cfm:

      <head>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
        <script type="text/javascript">
          $(document).ready(function(){
            $('#save').click(function(){
              $.ajax({
                url: 'add.cfc?method=addData&returnFormat=json',
                type: "post",
                data: { dataArray: [$('#test1').val(),$('#test2').val(),$('#test3').val() ] },
                dataType: 'json',
                success: function(data){
                  $('#result').html(data);
                }
              });
            });
          });
        </script>
      </head>
      <body>
        <form name="sub" method="post">
            Test1: <input type="text" name="test1" id="test1" /><br />
            Test2: <input type="text" name="test2" id="test2" /><br />
            Test3: <input type="text" name="test3" id="test3" /><br />
            <button type="button" id="save" name="save">Save</button>
        </form>
    
        <div id="result" />
    
      </body>
    

    add.cfc:

    <cfcomponent>
        <cffunction name="addData" access="remote" returntype="string" >
            <cfargument name="dataArray" type="array" />
    
            <cfset var result = "" />
    
            <cfloop array="#arguments.dataArray#" index="i" >
                <cfset result = result & "R: " & i & ", " />
            </cfloop>
    
            <cfreturn result />
    
        </cffunction>
    </cfcomponent>
    

    This example should get you going, just pass an array from javascript to ColdFusion, then loop that array in your cfc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following code works ok, except that it not zoom to the given points. If
The following code works perfectly. My only concern is that I wanna convert below
The following code works: List<JsonStock> stock = new List<JsonStock>(); foreach(tblStock item in repository.Single(id).tblStocks) stock.Add((JsonStock)
The following code works to get the status value of a if its enabled,
The following code works just fine. But it seems so verbose, surely there is
The following code works, but I'm wondering if the MemoryStream created is closed properly.
The following code works great in IE, but not in FF or Safari. I
The following code works for 90+ % of global security groups, but for one
The following code works fine: person = {:a=>:A, :b=>:B, :c=>:C} berson = {:a=>:A1, :b=>:B1,
The following code works as expected on CentOS and Ubuntu O/s but not on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.