brihol44
asked on
Coldfusion & Jquery $.ajax form update question
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...
my data for var "datax" looks like so...
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...
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);
}
});
};
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
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>
ASKER
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_2 50=95&cate gory_251=9 5&category _243=95&ca tegory_245 =95&catego ry_246=95& category_2 47=95&cate gory_248=9 5"}
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.
{"order":"category_249=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.
ASKER
I tried a couple of things. Just haven't worked with JSON data before. Is <cfset cfData=DeserializeJSON(the Data)> maybe answer to get it back out of JSON? Anyways, I did try using it but It's not quite working right.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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;
c'est dingue ! (amazing! :)
Open in new window