Results 1 to 2 of 2
  1. wfcentral's Avatar
    Posts
    75 Posts
    Global Posts
    76 Global Posts
       #1  
    I'm trying to pull a "name" and "points" out of a JSON data string I'm pulling from my server.

    I can get the following data from my server as "responseText"

    [{"username":"robert","points":"1000"}]

    I just can't figure out how to modify the code below so it passes "name" and "points" to the scene...

    I've been through numerous sites - prototype, javascript sites, palm dev sites... everything I try just gives me "order order" (meaning I'm doing something wrong)





    Code:
    var myAjax = new Ajax.Request(posturl, {
    	method: 'post',
    	evalJSON: 'force',
    	postBody: postdata,
    	contentType: 'application/x-www-form-urlencoded',
    		onComplete: function(transport){
    			if (transport.status == 200) 
    				myassistant.controller.get('area-to-update').update('Success!');
    			else {
    				myassistant.controller.get('area-to-update').update('Failure!');
    			}
    				myassistant.controller.get('server-response').update('Server Response: \n' + transport.responseText);	
    			},
    			onFailure: function(transport){
    				myassistant.controller.get('area-to-update').update('Failure!\n\n' + transport.responseText);
    			}
    			});
    		}
    }
  2. moserjj's Avatar
    Posts
    468 Posts
    Global Posts
    470 Global Posts
    #2  
    in your onSuccess function, you would do something like this to assign your responseText as a JSON object

    var r = transport.responseText.evalJSON();

    then, you could access the the values with r.username and r.points

Posting Permissions