Solved

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

Posted on 2013-11-17
4
212 Views
Last Modified: 2013-12-13
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
Comment
Question by:brihol44
  • 2
  • 2
4 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39655237
replace :
order: data,
by :
data: { order: data.split(",") },

Confirm it's << data >> and not << Data >> as you said you do alert(Data) !!!
0
 

Author Comment

by:brihol44
ID: 39655391
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
 
LVL 82

Expert Comment

by:leakim971
ID: 39655407
ok that mean it's already an array, good, so just use :

 data: { order: data },
0
 

Author Comment

by:brihol44
ID: 39655467
Ok, close I think... getting "Unknown column &#x27;item_59&#x27; in &#x27;field list&#x27;" on my cfc page.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now