[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2013-11-17
4
Medium Priority
?
232 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
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)
Suggested Courses

656 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