0

I am trying to follow this quesiton

How to retrieve value from elements in array using jQuery

like in my form. each table row has multiple inputs that are in the name attribute and it is an array.

<td><input type="number" name="quantity[]" class="form-control"></td>
<td><input type="number" name="unit[]" class="form-control"></td>
<td><input type="text" name="item_description[]" class="form-control"></td>
<td><input type="number" name="stock_no[]" class="form-control"></td>
<td><input type="number" name="eunitcost[]" class="form-control"></td>

and in my javascript code is this.

var counter = $("input[name^= 'quantity']").length;
        var array1 = $("input[name^= 'quantity']");
        var array2 = $("input[name^= 'unit']");
        var array3 = $("input[name^= 'item_description']");
        var array4 = $("input[name^= 'stock_no']");
        var array5 = $("input[name^= 'eunitcost']");
        var array6 = $("input[name^= 'ecost']");
        var i;
        for(i=0;i<counter;i++){
            $.ajax({
                url: 'http://localhost/pm/admin/service/user-service.php',
                type: 'POST',
                dataType: 'json',
                data: {
                    operation: 'pr-items',
                    pr_no: $('#prno').val(),
                    quantity: array1.eq(i).val(),
                    unit: array2.eq(i).val(),
                    item_description: array3.eq(i).val(),
                    stock_no: array4.eq(i).val(),
                    eunitcost: array5.eq(i).val(),
                    ecost: array6.eq(i).val

                },

                success: function(data) {
                    alert('pr items success');
                    //todo
                },
                error: function(data){
                    alert('pr items error');
                    //todo
                }
            });   
        }

what seems to be the problem why my arrays can't enter in ajax data?

4
  • The question is still a little unclear. What have you done to test this out? Are you receiving any values? Tell us what you've done so far and prove it, so that we know how you came up with this question Commented Aug 28, 2018 at 16:05
  • ajax isnt working. It doesn't alert either from success or error Commented Aug 28, 2018 at 16:32
  • 1
    Have you checked your ajax call in the dev tools' Network tab? Commented Aug 28, 2018 at 16:55
  • I can't seem find my ajax call in XHR ? Commented Aug 28, 2018 at 17:05

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.