0

I have an array of strings in my .js file and I am using $.get() to call a .cfm page to do a query (eventually) but would like to know how I can store the data sent using $.get() to a variable in my .cfm file.

.js

var obj = []; //array

//code to put strings in 'obj'

$.get("submit.cfm",{data: obj});

submit.cfm

<cfparam name="temp1" default="">
<cfset tempArr = ArrayNew(6)>

?. Do I want to use a < cfparam >, < cfset > or is there a better alternative?

The goal of submit.cfm is eventually to do something of the sorts:

<cfquery name="sample" datasource="database_live">
    SELECT temp1[1], temp1[2], etc....
    FROM table
</cfquery>
3
  • There are plenty of examples out there... search Ben Nadel Commented Jun 5, 2013 at 15:10
  • So the request to your page ends up looking something like submit.cfm?arr=foo,bar,fubar ? I'd use <cfparam name="URL.arr" default=""> Commented Jun 5, 2013 at 15:24
  • Duplicate? Commented Jun 5, 2013 at 15:26

1 Answer 1

1

Little confusing because you're naming your array variable "obj" but since it's actually an array... also looks like you array is simply an array of column names so you can simply do this...

instead of:

<cfparam name="temp1" default="">
<cfset tempArr = ArrayNew(6)>
<cfquery name="sample" datasource="database_live">
SELECT temp1[1], temp1[2], etc....
    FROM table
</cfquery>

Simply use:

<cfset tempArr = DeserializeJSON(URL.data) />
<cfquery name="sample" datasource="database_live">
    SELECT tempArr[1], tempArr[2], etc....
    FROM table
</cfquery>

If you want the query to be dynamic based on the number of items in your array then this:

<cfset tempArr = DeserializeJSON(URL.data) />
<cfset selectList = "" />
<cfloop array=#tempArr# index="i">
    <cfset selectList = listappend(selectList,i) />
</cfloop>
<cfquery name="sample" datasource="database_live">
    SELECT 
    <cfoutput>#selectList#</cfoutput>
    FROM table
</cfquery>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.