Results 1 to 4 of 4
  1.    #1  
    Hi, I'm working on precentral app and want to use ajax request to get youtube videos title, ...

    Code:
    		var request = new Ajax.Request(data, {
    			method: 'get',
    			evalJSON: 'force',
    			onSuccess: this.gotResults.bind(this),
    			onFailure: this.failure.bind(this)
    		});

    Code:
    AskAssistant.prototype.gotResults = function(transport) {
    	
    	$("youtubeTitle").update(transport.responseText);
    }
    So I use an Ajax Request which return something like this (transport.responseText) ....

    Code:
    {
     "version": "1.0",
     "encoding": "UTF-8",
     "entry": {
      "xmlns": "http://www.w3.org/2005/Atom",
      "xmlns$media": "http://search.yahoo.com/mrss/",
      "xmlns$gd": "http://schemas.google.com/g/2005",
      "xmlns$yt": "http://gdata.youtube.com/schemas/2007",
      "gd$etag": "W/\"DU4ARn47eCp7ImA9Wx9WFko.\"",
      "id": {
       "$t": "tag:youtube.com,2008:video:gzDS-Kfd5XQ"
      },
    and more....
    But I can't figure out how to extract values from this response.

    I tried transport.responseText.entry.xmlns this but it doesn't work

    Thanks for answers !
  2. #2  
    Try

    Code:
    AskAssistant.prototype.gotResults = function(transport) {
    	var json = transport.responseJSON;
    }


    Or you look easily for what is available

    Code:
    for (item in transport) {
    	// ## Use this for output
    	console.log(item + ' => ' + transport[item]);
    	// ## Or this
    	$("youtubeTitle").innerHTML += item + ' => ' + transport[item]);
    }
    Last edited by shifty64; 02/05/2011 at 06:54 AM.
  3. #3  
    Hey, you need to parse the response as JSON. do something like

    Code:
    var myresponse = JSON.parse(transport.responseText);
    then you have a JSON object that you can traverse with either the dot notation thing.object or square bracket notation thing['object']

    hope this helps!
    Creator of:

Posting Permissions