Results 1 to 2 of 2
  1.    #1  
    Hallo World,

    I send with 'get' data to my date.php and the responseText displayed [{'Data' : 'data'}] of my palm prprpr.

    I use responseJSON and $('mydiv').innerHTML = response.myfield; displayed nothing.

    See my code and help me!

    myPHP
    Code:
    <?PHP
    header('Content-type: application/json');
    error_reporting(E_ALL);
            ini_set('display_errors', 1);
    
    include 'palm_function.php';
    include 'config.php';
    
    .....
    
    
    
    
    .....
    
    
    $result = mysql_query($query);
    	
    	$all = array();
            while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
                $all[] = $line;
            }
    
    echo json_encode($all)."\n";
    ?>
    and my JSJSJS

    Code:
    //my send
    
    FriendzettelAssistant.prototype.handleseinZettelButtonPress = function(event){        
        
        email = this.textParameter;
        paxxus = '01902828zzz'; 
        
        
        var URL = "xxxx.php?adre=" + email + '&coxx=' + paxxus;
        seinZettel.mojo.activate();
    
        var request = new Ajax.Request(URL, {
    	method:'get',
            evalJSON: 'force',
    	onSuccess: this.myzettel.bind(this),
    	onFailure: this.fehler.bind(this)
    	
    });
        
        
        seinZettel.mojo.deactivate();
        
    }
    
    //my request
    
    FriendzettelAssistant.prototype.myzettel = function(transport) {
       //var response = transport.responseText || "Keine Verbindung mit dem Internet";
    //$('inhalt').innerHTML = 'response: ' + response;
    
     var json = transport.responseJSON;	
     $('inhalt').innerHTML = json['myfield_id'];
    
    }
    PHP version on my server is 5.2.13


    salute
  2. #2  
    Quote Originally Posted by uniqarts View Post
    Hallo World,

    I send with 'get' data to my date.php and the responseText displayed [{'Data' : 'data'}] of my palm prprpr.

    I use responseJSON and $('mydiv').innerHTML = response.myfield; displayed nothing.

    See my code and help me!

    myPHP
    Code:
    <?PHP
    header('Content-type: application/json');
    error_reporting(E_ALL);
            ini_set('display_errors', 1);
    
    include 'palm_function.php';
    include 'config.php';
    
    .....
    
    
    
    
    .....
    
    
    $result = mysql_query($query);
    	
    	$all = array();
            while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
                $all[] = $line;
            }
    
    echo json_encode($all)."\n";
    ?>
    and my JSJSJS

    Code:
    //my send
    
    FriendzettelAssistant.prototype.handleseinZettelButtonPress = function(event){        
        
        email = this.textParameter;
        paxxus = '01902828zzz'; 
        
        
        var URL = "xxxx.php?adre=" + email + '&coxx=' + paxxus;
        seinZettel.mojo.activate();
    
        var request = new Ajax.Request(URL, {
    	method:'get',
            evalJSON: 'force',
    	onSuccess: this.myzettel.bind(this),
    	onFailure: this.fehler.bind(this)
    	
    });
        
        
        seinZettel.mojo.deactivate();
        
    }
    
    //my request
    
    FriendzettelAssistant.prototype.myzettel = function(transport) {
       //var response = transport.responseText || "Keine Verbindung mit dem Internet";
    //$('inhalt').innerHTML = 'response: ' + response;
    
     var json = transport.responseJSON;	
     $('inhalt').innerHTML = json['myfield_id'];
    
    }
    PHP version on my server is 5.2.13


    salute
    You are returning your data in an array that is not JSON in the first place.

    If the data returned is in the format:

    [{}]

    then you need to do:

    {
    "something": [{}]
    }

    as the response (if I remember correctly).

    I know for a fact that you must do it (at least) in this way:

    Code:
    $('inhalt').innerHTML = json[0]['myfield_id'];
    The [0] is telling JavaScript to look for the first result in the array of JSON objects.

    Try the above first, and THEN if it doesn't work, simply wrap your JSON output with:

    Code:
    {
       "response": {JSON_GOES_HERE}
    }
    through this:

    Code:
    (...)
    echo "{\n";
    echo "   \"response\": ";
    echo json_encode($all)."\n";
    echo "}";
    ?>
    and you will then call the JSON within your app through:

    Code:
    $('inhalt').innerHTML = json.response[0]['myfield_id'];
    Arthur Thornton

    Former webOS DevRel Engineer at Palm, HP, and LG
    Former webOS app developer (built Voice Memos, Sparrow, and several homebrew apps and patches)
    Former blogger for webOS Nation and webOS Roundup

Posting Permissions