?
Solved

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

Posted on 2013-11-17
4
Medium Priority
?
229 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

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

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

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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)

777 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