0

I get the problem to create custom autonumber in dialog form jquery easy ui..

I Have the a function in controller like this..

public function getCode()
{
    if(!isset($_POST))  
        show_404();

    $query = "SELECT MAX(kode_barang) as maxID FROM tb_barang";
    $hasil = mysql_query($query);
    $data  = mysql_fetch_array($hasil);
    $idMax = $data['maxID'];
    $noUrut = (int) substr($idMax, 1, 4);
    $noUrut++;
    $newID = "B" . sprintf("%04s", $noUrut);
    $queryData  = $query->row_array();
    $phpVar     = array( "STATUS" => $newID); 
    echo json_encode ($phpVar) ;    
}

and I call that function from view, the javascript function like this..

<script> function makeAjaxCall()
{ 
    $.ajax({ 
        type: "post", 
        data: $('#form').serialize(), 
        url: "http://192.168.0.77/ci_jquery/barang/getCode", 
        cache: false,   
        success: function(json){        
        var obj = jQuery.parseJSON(json); 
        var r = obj['STATUS'];
        document.forms["form"]["kode_barang"].value = r;
    } 
});
} 
</script> 

And this is my dialog form.

<div id="dialog-form" class="easyui-dialog" style="width:300px; height:400px; padding: 10px 20px" closed="true" buttons="#dialog-buttons">
    <form id="form" method="post" novalidate>
        <table border="0">
            <tr>
                <div class="form-item">
                <td width="100"><label for="type">Kode Barang </font></td>
                <td><input type="text" name="kode_barang"/></td>
            </tr>
</div>

Thanks for reply and attention.

okywijaya
  • 59
  • 2
  • 13
  • Ok - and your question is? –  Oct 16 '13 at 03:57
  • Start with basic debugging: check the values in your POST request, and the values being returned by your PHP script. Make sure you're getting what you expect to get. That will pin down where the problem is in your code. –  Oct 16 '13 at 04:02
  • I think my simple problem is how to create autonumber in jquery easy ui.. :) Actually i m not post a variable, i just want get value from $query = "SELECT MAX(kode_barang) as maxID FROM tb_barang"; – okywijaya Oct 16 '13 at 04:05

2 Answers2

1

I assume your getCode() function fails. You are using the $query as an object however it is just a string..

$query = "SELECT MAX(kode_barang) as maxID FROM tb_barang";
$queryData  = $query->row_array();

You should be getting an error saying that you are calling row_array() on a non-object. You should remove this line as it is not even used.

You should at least test your PHP code before using it with any other scripts/functions. This is in addition to turning error reporting on in PHP in your development environment to show things like this.

Community
  • 1
  • 1
immulatin
  • 2,118
  • 1
  • 12
  • 13
  • I dont understand to debug with your suggest, usually i find debug with echo and alert :p.. thanks for reply immulatin. – okywijaya Oct 16 '13 at 04:08
1

Try this:

You can do this by using jquery Ajax in your javascript function.
Set url parameter in ajax with file and function name.

-

Thanks

Anand Solanki
  • 3,419
  • 4
  • 16
  • 27