Reputation: 115
I am trying to send an array from an html page to an asp proxy (to a service), but cannot get the array to work properly.
Array Type: json
Scripting: JavaScript/jquery
var order = new Array();
for (var i = 0; i < list.length; i++) {
if (list[i].included == true)
order.push({ MarketID: list[i].marketID, Crop: list[i].crop })
}
$("#orderValue").val(order.join());
...
<form action="/hd.asp" method="post" id="hdForm">
<input type="hidden" name="order" id="orderValue" />
...
</form>
Removing the array, it works properly, but the array is required property. I have tried just sending array, using .join(), and few other things, but nothing seems to be working.
Upvotes: 1
Views: 2423
Reputation: 4517
[EDIT] c.hill got there first :$ [/EDIT]
Don't use join()
, use JSON.stringify()
, e.g.:
var doit = function( myArray ) {
var arrayString = JSON.stringify( myArray );
$('#orderValue').val( arrayString );
// rest of code
}
Upvotes: 0
Reputation: 3233
Try this:
$("#orderValue").val(JSON.stringify(order));
Edit.. Oops, should have put order inside of JSON.stringify() as an argument. Try it now.
Upvotes: 1