contoh script JSON (JQuery Framework) AJAX PHP

ada 3 file yg di perlukan

– view.php
– load.php

view.php: sebagai html view / melakukan pemanggilan post ajax

<script type="text/javascript" src="jquery-1.6.4.min.js"></script>
<script type='text/javascript'>
    function  load_combobox_kabkota(val){
        $.post("./load.php", { 'kode' : val },
                var strbody = '';
                for(var i in data){
                    var nomor = i; nomor++;
                     strbody += "<option value='"+data[i].id+"'>";
                     strbody += data[i].kota+"</option>";
            }, "json");

<select id='id_propinsi' name='div_propinsi'>
    <option value='31'>DKI Jakarta</option>
    <option value='32'>Jawa Barat</option>
<br />
Kab/Kota :
<select name='id_kabkota' id='id_kabkota'>


load.php: menerima nilai post, dan mengirim balik nilai array

$b = array
		array('id'=>311, 'kota'=>'Jakarta Barat'),
		array('id'=>312, 'kota'=>'Jakarta Timur'),
		array('id'=>313, 'kota'=>'Jakarta Selatan'),
		array('id'=>314, 'kota'=>'Jakarta Utara'),
		array('id'=>315, 'kota'=>'Kep. Seribu')
$b = array
		array('id'=>321, 'kota'=>'Bogor'),
		array('id'=>322, 'kota'=>'Sukabumi'),
		array('id'=>323, 'kota'=>'Cianjur')
$pilih = $_POST['kode'];

if($pilih == '31') 
	echo json_encode($a);
	echo json_encode($b);



Published by


just to remember what i had known :)

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s