1. #1
    Sencha User
    Join Date
    May 2012
    Location
    Moscow, Russia
    Posts
    10
    Vote Rating
    0
    Qwentor is on a distinguished road

      0  

    Default How to get simple response from server without using data.store?

    How to get simple response from server without using data.store?


    I want to check the input data for existence on the server. The data must be sent to server and then I must get the answer true/false. For example if data already exists and because not saved - true, else false.

  2. #2
    Sencha User
    Join Date
    Jun 2011
    Location
    Ukraine, Mykolayiv
    Posts
    99
    Vote Rating
    1
    rsqw is on a distinguished road

      0  

    Default


    Ext.Ajax.request({
    url: "/cool/url",
    method: "POST",
    params: {
    coolParam: "coolValue"
    },
    success: MY_COOL_SUCCESS_CALLBACK
    failure: MY_COOL_FAILURE_CALLBACK
    });


    To make a cross-domain request use:
    Ext.data.JsonP.request

    Hope this helps

  3. #3
    Sencha User
    Join Date
    May 2012
    Location
    Moscow, Russia
    Posts
    10
    Vote Rating
    0
    Qwentor is on a distinguished road

      0  

    Default


    I can't understand how to do it in PHP code
    I've done so:
    ExtJS:
    Code:
    Ext.Ajax.request({
                                            url: "add.php",
                                            params: {
                                                number: text
                                            },
                                            success: function(){
                                                store.insert(0, new User());
                                                var record = store.getAt(0);
                                                var dataIndex = 'Number';
                                                record.beginEdit();
                                                record.set(dataIndex, text);
                                                record.endEdit();                                                                                        
                                            },
                                            failure: function() {
                                                Ext.Msg.alert('Failure!', 'This number already exists!');
                                            }
                                        });
    PHP:
    PHP Code:
    <?php
    header
    ('Content-Type: text/html; charset=UTF-8'); 

    if (
    $db = @mysql_connect("localhost""root""123456")) { 
       
    mysql_select_db("test2"); 
       
    mysql_query("SET NAMES utf8"); 

       
    $number $_POST['number'];
       
    $queryString "Select `Number` FROM `table2` WHERE `Number` = '".$number."'";
       
    $data mysql_query($queryString);
       
    $rows mysql_num_rows($data);
       if(
    $rows) {
            echo 
    '{"success":"false"}';
       }
       else {
      
        
    $queryString "INSERT INTO `table2` (`Number`) VALUES ('".$number."')";
        
    mysql_query($queryString);
        echo 
    '{"success":"true"}';
        }
      
    mysql_close($db);
    }
    ?>
    But alert not works and new row is always added to grid, but if it contains data that already exists on server then this data not saved after reload page.
    Therefore program always gets success: true. Why? What do I do wrong?

  4. #4
    Sencha User
    Join Date
    Jul 2011
    Location
    indonesia
    Posts
    6
    Vote Rating
    1
    hendrisoni is on a distinguished road

      0  

    Default Ext.decode

    Ext.decode


    You can use Ext.decode()

    Code:
    Ext.Ajax.request({
        url : "add.php",
        params : {
            number : text
        },
        success : function(response) {
            response = Ext.decode(response.responseText)
            if(response.success) {
                store.insert(0, new User());
                var record = store.getAt(0);
                var dataIndex = 'Number';
                record.beginEdit();
                record.set(dataIndex, text);
                record.endEdit();
            }
        }
    });
    Last edited by hendrisoni; 3 Jun 2012 at 6:45 AM. Reason: change [php][/php] to [code]

  5. #5
    Sencha User
    Join Date
    May 2012
    Location
    Moscow, Russia
    Posts
    10
    Vote Rating
    0
    Qwentor is on a distinguished road

      0  

    Default


    Thanks! It helps me. But I've used if(response.success == 'true'),
    if(response.success) not works

  6. #6
    Sencha User
    Join Date
    Jul 2011
    Location
    indonesia
    Posts
    6
    Vote Rating
    1
    hendrisoni is on a distinguished road

      0  

    Default


    it is because that is sent from php not an object. try,

    PHP Code:
    echo json_encode(array('success' => true)); 

  7. #7
    Sencha User
    Join Date
    May 2012
    Location
    Moscow, Russia
    Posts
    10
    Vote Rating
    0
    Qwentor is on a distinguished road

      0  

    Default


    Thanks!

Thread Participants: 2