1. #1
    Sencha User
    Join Date
    Oct 2012
    Location
    Toulouse
    Posts
    60
    Vote Rating
    0
    Answers
    7
    novadys-sbu is on a distinguished road

      0  

    Default Answered: Another JSON decode problem

    Answered: Another JSON decode problem


    Hello everyone,

    This is probably a silly mistake I've done somewhere, but I can't find it for the life of me.
    I have a form to submit. The data from the form needs to go to a PHP treatement which then should send back a JSON string.

    This is my form being submit :

    Code:
    confirmButton:{                tap: function(list, index, element, record){
                        Ext.getCmp('searchForm').submit({
                            method : 'POST',
                            url: 'servlets/testSearch.php',
                            success: function(responsiveObject){
                               eval(responsiveObject.responseText); // Return string not null
                               alert(myResponse.success);
                            }
                        }); //End of tap                                
                    }  
                }
    and here is my PHP :
    PHP Code:
    <?
    phprequire_once 
    ("..\\..\\config\\system.inc.php");    
    $search = ($_POST['searchString']);    
    $strData "var myResponse={success:\"".$search."\", file:\"".$search."\"};";    
    echo 
    $strData//is returned to JS    ?>
    And I get the following error :
    Uncaught Error: You're trying to decode an invalid JSON String: var myResponse={success:"hello", file:"hello"};



  2. Remove the 'var myResponse='. Your response should look like this, note the double quotes around the keys:

    Code:
    {    "success": "hello",
        "file": "hello"
    }
    Use jsonlint.com to validate your JSON feeds, paste the feed in there and it'll help you.

  3. #2
    Sencha User
    Join Date
    Nov 2011
    Location
    England
    Posts
    135
    Vote Rating
    7
    Answers
    11
    george.m is on a distinguished road

      0  

    Default


    Remove the 'var myResponse='. Your response should look like this, note the double quotes around the keys:

    Code:
    {    "success": "hello",
        "file": "hello"
    }
    Use jsonlint.com to validate your JSON feeds, paste the feed in there and it'll help you.

  4. #3
    Sencha User
    Join Date
    Oct 2012
    Location
    Toulouse
    Posts
    60
    Vote Rating
    0
    Answers
    7
    novadys-sbu is on a distinguished road

      0  

    Default Perfect !

    Perfect !


    Thanks for that and for the link. You are a star

  5. #4
    Sencha User
    Join Date
    May 2013
    Posts
    20
    Vote Rating
    0
    chamijain is on a distinguished road

      0  

    Default Email formpanel details using php or any other method

    Email formpanel details using php or any other method


    I have a form in my page. I want the form details, which are filled by user, to send on a particular email.
    Here is my Form:

    Code:
    xtype: 'formpanel',            
    width: 300,            
    height: 900,//recommended for the build            
    url: 'contact.php',            
    scrollable:false,            
    items:[                    
    {                        
    xtype: 'textfield',                        
    name : 'name',                        
    label: 'Name',                        
    labelWidth:100                    
    },                    
    {                        
    xtype: 'textfield',                        
    name : 'Date of birth',                        
    label: 'Date of birth',                        
    maxLength: 10,                        
    labelWidth:120                   
     },                    
    {                        
    xtype: 'textfield',                        
    name : 'Nationality',                        
    label: 'Nationality',                        
    labelWidth:100                    
    },                    
    {                        
    xtype: 'textfield',                        
    name : 'City of Residence',                        
    label: 'City of Residence',                        
    labelWidth:170                   
     },                   
     {                        
    xtype: 'textfield',                        
    name : 'Country',                        
    label: 'Country',                        
    labelWidth:100                  
      },                                      
    {                        
    xtype: 'textfield',                        
    name : 'Date',                        
    label: 'Starting date of this course',                        
    labelWidth:220                   
     },                   
     {                        
    xtype: 'fieldset',                        
    title: '3. Course to join',                        
    items: [                            
    {                                
    xtype: 'selectfield',                                
    label: 'Choose one',                                
    labelWidth:120,                                
    options: [                                  
     {
    text: 'Ayurveda Massage (Ayurveda Yoga Massage)',  value: 'first'},                                    
    {
    text: 'Ayur Balance Massage', value: 'second'},                                   
     {
    text: 'Abhyanga Massage with Shirodhara',  value: 'third'}                              
      ]                           
     }                      
      ]                   
     },                  
      {                        
    xtype: 'numberfield',                        
    name : 'Date',                        
    label: 'Starting date of this course',                        
    labelWidth:220                    
    },                   
     {                        
    xtype: 'numberfield',                        
    name : 'Your Phone',                        
    label: 'Your Phone',                        
    labelWidth:120                    
    },                    
    {                        
    xtype: 'toolbar',                        
    items: [                           
     {                                
    xtype: 'button',                                
    height: 30,                                
    text: 'Submit',                                
    ui      : 'confirm',                                
    handler : function(button) {                                    
    this.up('formpanel').submit();                                
    }                            
    }                       
     ]                   
     }               
     ]


    Here is my php script:

    Code:
    <?php// Configuration Settings$SendFrom =    "Form Feedback <jainishan@yahoo.in>";$SendTo =      "ishan.fzd@gmail.com";$SubjectLine = "Feedback Submission";// Send E-Mail and Direct Browser to Confirmation Pagemail($SendTo, $SubjectLine, $MsgBody, "From: $SendFrom");?>



    On tap of form button, I am getting a following exception:
    You're trying to decode an invalid JSON String:
    Parse error: syntax error, unexpected '.=' (T_CONCAT_EQUAL) in E:\softwares\Sencha dwnlds\xampp\htdocs\RasovaiApp\contact.php on line 11

    Any help would be greatful.
    Thanks Ishan jain

Thread Participants: 2

Tags for this Thread