0

I am using Jquery an dynamically creating number of rows. if I want to send it to server how can I send that data. I tried using form but that did not work

I am using the following code:

                 $(document).ready(function() {
        // Add button functionality
        $("table.dynatable button.add").click(function() {
            var master = $(this).parents("table.dynatable");
                         var prot = master.find(".prototype").clone();
            prot.attr("class", "")
            master.find("tbody").append(prot);
        });

In the body I have:

            <th>Numbere</th>
            <th><button class="add">Add</button></th>
        </tr>

Also here why do we need

        prot.attr("class", "")

I am able to add dynamically the number of entries I want. But having issue sending this data to the server using HTTP.

I want to use Ajax call but how to extract and get the data here.

$.ajax({
url: "/temp",
type: "post",
data: data,
dataType: "json",
contentType: 
4
  • You are adding some new fields to the form. But you are using cloning so do you change names of those fields ? If not then there will be only one value in your http request Commented Apr 27, 2013 at 19:32
  • yes this is the problem I am looking how to address Commented Apr 27, 2013 at 19:39
  • Maybe you can use brackets in the prototype name i.e. <input type='text' name='testField[]'> It should help if you are using PHP on server side. If not you can use: prot.attr('name', 'someNewName'); But remember that you should change id also Commented Apr 27, 2013 at 19:46
  • why won't a form work.... and then use serialize()? Commented Apr 27, 2013 at 20:20

1 Answer 1

2

You can extract data from an HTML table to an associative array (JSON object) and then post it to the server

How to extract data into associative array from HTML table using jQuery?

http://encosia.com/use-jquery-to-extract-data-from-html-lists-and-tables/

Sign up to request clarification or add additional context in comments.

2 Comments

in my case I am using clone and my list is dynamic and all the variables are having the same name. than how to address this
@TheLearner it shouldn't matter as long as you are iterating all the rows correctly. can you share what you have already tried?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.