brihol44
asked on
Coldfusion $.ajax delete from data string of values
I'm submitting two types of fields...
1. Main Categories
2. Sub-Categories
I've created a form that submits the data just fine to the function below. The example data might be...
cat_48=0&rec_174=1&cat_47= 0&rec_172= 1&rec_173= 0
I'm a little stuck on separating the two out with deleting them from two separate tables on my func_data.cfm page. So if it's "cat_..." delete from one table. If it's "rec_..." delete from the other. I was thinking I could treat the data as a list and loop through it but it's not a list
1. Main Categories
2. Sub-Categories
I've created a form that submits the data just fine to the function below. The example data might be...
cat_48=0&rec_174=1&cat_47=
I'm a little stuck on separating the two out with deleting them from two separate tables on my func_data.cfm page. So if it's "cat_..." delete from one table. If it's "rec_..." delete from the other. I was thinking I could treat the data as a list and loop through it but it's not a list
function delete_cats_and_records() {
myDataString = $("#userData").serialize();
$.ajax({
type: "POST",
url: "func/func_data.cfm",
data: myDataString,
cache: false,
success: function() {
getData();
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
})
};
ASKER
thx for the help. 0 = don't delete (default value), 1 = delete.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok agx.. that makes sense, cleaner and something I'm more familiar on how to do on the func_data.cfm page. I guess I didn't know how to do that (lists) using jquery with using the
myDataString = $("#userData").serialize() ; to grab the values.
myDataString = $("#userData").serialize()
function delete_cats_and_records() {
myDataString = $("#userData").serialize();
$.ajax({
type: "POST",
url: "func/func_data.cfm",
data: myDataString,
cache: false,
success: function() {
getData();
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
})
};
Sorry I had to run out. Hm.. I'm not sure serialize will work here if it assigns elements unique names. Might have to generate the list yourself using something like this:
https://www.experts-exchange.com/questions/24225776/jQuery-get-val-of-multiple-checked-checkboxes.html
https://www.experts-exchange.com/questions/24225776/jQuery-get-val-of-multiple-checked-checkboxes.html
ASKER
thx Agx... I figured out the jquery list thing on my own.
<cfloop collection="#URL#" item="param">
<!-- split out field name and id: "cat" and "48">
<cfset name = getToken(param, 1, "_")>
<cfset id = getToken(param, 2, "_")>
<cfset value = URL[param]>
<!--- its a category with a valid ID ...--->
<cfif name eq "cat" and ID gt 0>
CATEGORY: do something with #id# and #value# ...
<cfelseif name eq "rec" and ID gt 0>
REC: do something with #id# and #value# ...
</cfif>
</cfloop>
But I'm wondering if there's an easier way ... I'm assuming the 48 in "cat_48=0" represents a category id. What does the value ie 0/1 represent?