Essentially, what i am trying to do is upgrade an old app i created to use some of the great AJAX features of jquery. Example: instead of limiting the admin to creating categories one at a time which can obviously be really monotonous, I would like to convert the page so that you can dynamically add a field so you can add multiple categories at once if desired…my issue now is, how do i go about properly posting the data via php? Here is what i am working with:
Keep in mind i am planning on using AJAX to post the data…Let me know if you have any ideas for improving or anything that can help at all.
First of all,
var cats = $("#categoryTable tr").length;
won’t work because if you remove one (not the last) and then add one, you will have duplicate Id’s and names… Maybe you should just do a cats++ every time you add a cat.
Secondly, Itterate through your inputs and bulid your POST data like:
var postData = '?';
( I think)
I’m sure there are better ways though…
instead of dynamically generating a new name for each category (category_2, category_3, category_4, etc..), why not just make “category” an array?
– never worry about duplicate
– _much_ easier to manage server-side.
– if you don’t need the
ids (it doesn’t seem like you do), just omit them, and you won’t need to do
cats++ or anything, you could just clone and append and be done with it.
as a side note,
.live() is depreciated.
.on() is currently the preferred method to attach event handlers (or, use
.delegate() with older versions of jQuery).
Thanks for the thought, I will have to find something that teaches that…I pieced together some code to pull this together…I do know that
.live() is deprecated, I am trying to go one step at a time so i can at least get it functioning while i am learning. Thanks for your input!
I’d aggre with @traq for the array thing… You’ll have to worry for one thing less…
anyway, in the code I suggested, you are supposed to use the variable postData to your AJAX request like this
then, at the phpPage.php you’ll handle your POST data…
and if you don’t already, visit api.jquery.com – a lot of what I did is straight from the examples there.
You must be logged in to reply to this topic.