1

I am trying to pass an arbitrary amount of arrays from my javascript to a php file with json through ajax, the problem word is arbitrary, assume following allmost-development-code

var arrayContaingAll;
$("li", "#list").each(function()
{
 var a = array( $(".name",this).val(), $(".unit",this).val(), $(".amount", this).val() );
 arrayContainingAll[] = a;
});

however, the [] functionality on an array does not work for me, how would i go around implementing such feature?

Yes, i know PHP damaged me thinking that way

Dave Child
7,9542 gold badges28 silver badges37 bronze badges
asked Mar 10, 2011 at 18:35

2 Answers 2

5
arrayContainingAll.push(a); //equavalent in JavaScript to PHP's arrayContainingAll[] = a;
answered Mar 10, 2011 at 18:37
Sign up to request clarification or add additional context in comments.

Comments

2
var arrayContaingAll=[];
$("li", "#list").each(function()
{
 var tempArray=[];
 tempArray.push($(".name",this).val());
 tempArray.push($(".unit",this).val());
 tempArray.push($(".amount",this).val());
 arrayContainingAll.push(tempArray);
});
//arrayContaingAll is ready

//to optimize ur code you may cache li like this inside each

var li= $(this);
tempArray.push(li.find('class_Name'));
answered Mar 10, 2011 at 18:38

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.