• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 234
  • Last Modified:

Coldfusion argument collection using $.ajax is creating a missing variable error

Hello, I've created a sortable list that I want to be able to order a list of items and for it to save by using $.ajax. I can't seem to figure this out.

	function persist() {
	    var data = $("#sortable").sortable('toArray');

			$.ajax({
			   url: "app/func/data.cfc",
			   method: "saveData",
			   dataType: "json",
			   order: data,
			   success: function () {
                              alert("yes!");
			   }
			});
    }



<cfcomponent output="false">

<cffunction name="saveData" access="remote" returnType="void" output="false">
	<cfargument name="order" type="any" required="true">
	<cfset var x = "">
	<cfset var id = "">
	<cfset var item = "">

	<!--- loop through and make a new order --->
	<cfloop index="x" from="1" to="#listLen(arguments.order)#">

		<cfset item = listGetAt(arguments.order, x)>
		<cfset id = listGetAt(item,2,"_")>

		<cfquery datasource="dbvizz" username="root" password="">
		UPDATE column
		SET sort_order = #item#
		WHERE record_id = #id#
		</cfquery>
	</cfloop>

</cffunction>

</cfcomponent>

Open in new window




The values I'm getting when I add alert(Data) is "item_59,item_60,item_61,item_62,item_63,item_64" so that's correct. I understand that I might have to deserialize my data or something but I'm looking to get a coded solution. I've found a few examples out there and I haven't been able to get those to work. My code above is at it's basic level.
0
brihol44
Asked:
brihol44
  • 2
  • 2
1 Solution
 
leakim971PluritechnicianCommented:
replace :
order: data,
by :
data: { order: data.split(",") },

Confirm it's << data >> and not << Data >> as you said you do alert(Data) !!!
0
 
brihol44Author Commented:
Thx for the help...

When I add that I get "data.split is not a function". I did make sure that I'm using case sensitivity "data" by the way.

      function persist() {
          var data = $("#sortable").sortable('toArray');

                  $.ajax({
                     url: "app/func/data.cfc",
                     method: "saveData",
                     dataType: "json",
                     data: { order: data.split(",") },
                     success: function (respJSON) {
                        jsonStruct = respJSON;
                     }
                  });
    }
0
 
leakim971PluritechnicianCommented:
ok that mean it's already an array, good, so just use :

 data: { order: data },
0
 
brihol44Author Commented:
Ok, close I think... getting "Unknown column &#x27;item_59&#x27; in &#x27;field list&#x27;" on my cfc page.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now