Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Coldfusion & Jquery $.ajax form update question

Posted on 2014-03-20
6
Medium Priority
?
597 Views
Last Modified: 2014-03-21
I have a form... with rows of data. In those rows I have a select menu to where I can reorder the rows of data into different categories. When I click submit on adjusting various select menus. I run the following script...

	function reorder_data_in_categories() {

		var data = $("[id=dataCategory]").serialize();
		var datax = "order=" + data;

		alert(datax);

			$.ajax({
				 url: "app/inc/inc_categorization.cfm",
				 data: datax,
				 success: function () {
				 	getData();
				 },
				 error: function (xhr, ajaxOptions, thrownError) {
				 alert(xhr.status);
				 alert(thrownError);
				 }
		});

	};

Open in new window


my data for var "datax" looks like so...

order=category_247=96&category_248=95&category_249=95&category_250=95&category_251=95&category_243=95&category_245=95&category_246=95

Open in new window


only the first record is being updated probably because of the & signs and "Order" is defining the first value. Just trying to loop through all of the values to update all records in the data string.

On inc_categorization.cfm I have...

<cfloop index="x" from="1" to="#listLen(order, "&")#">

	<cfset package = listGetAt(order, x)>

	<cfset recordID = listGetAt(package,2,"_")>

	<cfset value = listGetAt(recordID,2,"=")>

	<cfset recordID = listGetAt(recordID,1,"=")>

	<cfquery stuff


</cfloop>

Open in new window

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
  • 3
  • 3
6 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 39945453
What about :
	function reorder_data_in_categories() {

		var data = $("[id=dataCategory]").serialize();
		var datax = { order: data };

		alert( JSON.stringify(datax) );

			$.ajax({
				 url: "app/inc/inc_categorization.cfm",
				 data: datax,
				 success: function () {
				 	getData();
				 },
				 error: function (xhr, ajaxOptions, thrownError) {
				 alert(xhr.status);
				 alert(thrownError);
				 }
		});

	};

Open in new window

0
 

Author Comment

by:brihol44
ID: 39945589
ok, thx. I see the data is formatted into a json string but by cfm code (listed above) is now causing issues with the json format.

{"order":"category_249=95&category_250=95&category_251=95&category_243=95&category_245=95&category_246=95&category_247=95&category_248=95"}

Oh and I know that I'm suppose to use .cfc's as you directed (I think it was you :)  .. ) me a month ago or so which I have been doing in any new projects but for consistency for this project I'm using .cfm for the ajax calls.
0
 

Author Comment

by:brihol44
ID: 39945610
I tried a couple of things. Just haven't worked with JSON data before. Is <cfset cfData=DeserializeJSON(theData)> maybe answer to get it back out of JSON? Anyways, I did try using it but It's not quite working right.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 39945653
Try to replace :
var data = $("[id=dataCategory]").serialize();
            var datax = { order: data }
by :
var data = $("[id=dataCategory]").serialize().split("&");
            var datax = { order: data }

it will create a JSON objetc like that :
{
    object: ["category_249=95", "category_250=95", "category_251=95" ,...]
}

or maybe just :
var data = $("[id=dataCategory]").serialize().split("&");
            var datax =data;

so you just need to loop over the array
0
 

Author Comment

by:brihol44
ID: 39945707
Cool! Worked. Thx leakim971! Just for those that need the guidance... I did need to add.
var data = $("[id=dataCategory]").serialize().split("&");
            var datax = "order=" + data;

Open in new window

0
 
LVL 82

Expert Comment

by:leakim971
ID: 39945710
c'est dingue ! (amazing! :)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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 …
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
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…
Suggested Courses

730 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