1. #1
    Ext User
    Join Date
    Jul 2008
    Posts
    6
    Vote Rating
    0
    souvik is on a distinguished road

      0  

    Default Problem in HttpProxy

    Problem in HttpProxy


    I have a problem ...
    Please do reply sir,
    I have written a code to populate a drop down menu from the mysql database. But after trying out many debugging fuda I find out that the php code I have written id running fine but the javascript page is not interacting with the php code to collect data from Json.

    My PHP code:-
    <?php
    include 'dbconnect.php';
    $task = '';
    if ( isset($_POST['task'])){
    $task = $_POST['task']; // Get this from Ext
    }
    switch($task){
    case "LISTING": // Give the entire list
    getList();
    break;
    default:
    echo "{failure:true}";
    echo "testing failure ";
    echo $_POST['task'];
    echo $task; // Simple 1-dim JSON array to tell Ext the request failed.
    break;
    }
    function getList()
    {
    $query = 'SELECT `COMP_NAME`,`COMP_STATUS`,`COMP_ID` FROM `crm_company` ORDER BY `COMP_NAME`';
    $result = mysql_query($query);
    $nbrows = mysql_num_rows($result);
    if($nbrows>0){
    $rec = mysql_fetch_array($result);
    $arr[] = $rec;
    $jsonresult = JEncode($arr);
    echo '({"total":"'.$nbrows.'","results":'.$jsonresult.' })';

    } else {
    echo '({"total":"0", "results":""})';

    }
    }
    function JEncode($arr){
    if (version_compare(PHP_VERSION,"5.2","<"))
    {
    require_once("./JSON.php"); //if php<5.2 need JSON class
    $json = new Services_JSON(); //instantiate new json object
    $data=$json->encode($arr); //encode the data in json format
    } else
    {
    $data = json_encode($arr); //encode the data in json format
    }
    return $data;
    }
    ?>


    My javascript page:

    Ext.onReady(function(){
    Ext.QuickTips.init();

    // simple array store
    var store1 = new Ext.data.Store({
    id: 'store1',
    proxy: new Ext.data.HttpProxy({
    url: "weldb.php", // File to connect to
    method: 'POST'
    }),
    baseParams:{task: "LISTING"}, // this parameter asks for listing
    reader: new Ext.data.JsonReader({ // we tell the datastore where to get his data from
    root: 'results',
    totalProperty: 'total',
    id: 'id'
    },[
    {name: 'COMP_NAME', type: 'String', mapping: 'COMP_NAME'},
    {name: 'COMP_STATUS', type: 'string', mapping: 'COMP_STATUS'},
    {name: 'COMP_ID', type: 'string', mapping: 'COMP_ID'}
    ]),
    sortInfo:{field: 'COMP_NAME', direction: "ASC"}
    });
    store1.on('loadexception', function(httpProxy, o , response) {
    Ext.MessageBox.show({
    title:'An Exception has occurred',
    msg: 'The server has encountered a problem and is unable to retrieve your data.' + response,
    buttons: Ext.Msg.OK
    });
    } );

    var combo = new Ext.form.ComboBox({
    store: store1,
    displayField:'COMP_NAME',
    typeAhead: true,
    mode: 'local',
    triggerAction: 'all',
    emptyText:'Select a Company...',
    selectOnFocus:true,
    applyTo: 'comb'
    });
    });

  2. #2
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,505
    Vote Rating
    53
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    Posting the same question in multiple forums and as PMs to individuals is hardly likely to make people want to help.

    Also, format the code so we can read it.

  3. #3
    Ext User
    Join Date
    Jul 2008
    Posts
    6
    Vote Rating
    0
    souvik is on a distinguished road

      0  

    Default sorry

    sorry


    Sorry for questioning in multiple forums. but I need the help very badly and urgently. I'm now in office and I've to go home after fininshing this job . As you are online now , this is my earnest request to help me as quick as possible.

Thread Participants: 1