Reputation: 3
I have a webpage with the following input:
<input type='text' name='packagedims[]' value='1' id='packagedims' title='Package1' />
I'm using it in jQuery as so:
var packagedims = $('input#packagedims').serialize();
and then I'm using jQuery.ajax to post it to my php file:
'&packagedims=' + packagedims
(I know I could use Serialize() on the whole form but I'm modifying existing code so haven't got round to doing that yet. In the above line I'm sending individual variables to php.)
When I test the output using alert() I get the following:
&packagedims=packagedims%5B%5D=1&packagedims%5B%5D=2
I just wanted to check that this sort of output is correct and that using unSerialize() in my php file will be able to split this into a proper array.
Thank you,
Upvotes: 0
Views: 794
Reputation: 817130
.serialize()
[docs] already returns a string in the form of
key=value&key=value&...
Don't append to something else, otherwise it becomes
key=key=value&...
which is incorrect. So do not concatenate it with '&packagedims='
.
There is no need to use any unserialize function in PHP. The data will be sent as GET or POST data and be available in PHP through $_GET
or $_POST
. E.g. if you make a POST request, $_POST['packagedims']
will be an array containing the values.
Variables From External Sources might be worth a read.
Upvotes: 4