Solved

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

Posted on 2013-11-17
4
226 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 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

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

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

Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

729 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