Jquery Post Input Array PHP

you have form html with array input, and you want to save it with jquery post (ajax)


the html code looks like


with jquery you need get value from array input which checked and with ask class, use …

input-array-get-valueyou need var object data

at last, change the object or array value to json string, so you can send it with POST method


and test in receiver file (simpan.php) you must decode the json string


test with var_dump

dump-json-arraycomplete html code


<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<div id='div-polling-ajax-module'>
<li>Sebagai interviewer persiapan apa saja yang Anda lakukan sebelum sesi interview ?
<ul  style="list-style-type: none;">
<input type="radio" ask="1" value="1" name="ask[1]">Membaca CV
<input type="radio" ask="1" value="2" name="ask[1]">Mencari informasi tentang profil kandidat melalui jejaring sosial
<input type="radio" ask="1" value="3" name="ask[1]">Kedua jawaban diatas kurang tepat
<li>Pertanyaan apa yang sering Anda ajukan kepada kandidat pada saat sesi interview?
<ul  style="list-style-type: none;">
<input type="radio" ask="2" value="4" name="ask[2]">Seputar personality
<input type="radio" ask="2" value="5" name="ask[2]">Seputar keluarga
<input type="radio" ask="2" value="6" name="ask[2]">Seputar background informasi
<input type='hidden' value='1' id='id_pool'/>

<button id='send_polling' class='btn btn-info'>Save</button>
<button id='view_polling' class='btn btn-warning'>View</button>

$(document).ready(function() {
$('#send_polling').click(function(){ save_poling(); });
$('#view_polling').click(function(){ view_poling(); });


function save_poling(){

var data = {};
$.each($('input:radio:checked.ask'), function(){ data[$(this).attr('ask')] = this.value; });


{'id_pool':$('#id_pool').val(), 'ask':JSON.stringify(data) },

function (data){ $('#nav-list-form').html(data); }


function view_poling(){


complete php code


$post = json_decode($_POST['ask']);



Published by


just to remember what i had known :)

4 thoughts on “Jquery Post Input Array PHP”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s