Ver Mensaje Individual
  #3 (permalink)  
Antiguo 09/01/2013, 01:16
dzirpeld
 
Fecha de Ingreso: enero-2013
Mensajes: 1
Antigüedad: 11 años, 3 meses
Puntos: 0
Respuesta: Acceder a datos JSON con jQuery

Tengo un problemilla a ver si alguien me podría ayudar, estoy intentando mostrar los reultados de este API, si pongo la URL (la cual he puesto modificada por aqui por seguridad) en el navegador, me aparece un array con todas las noticias publicadas, pero no se como mostrar los resultados en la web.

Si alguien me puede ayudar se lo agradeceria muchisimo. os dejo el código que tengo por si me podeis ayudar a mostrar el contenido del API.

Muchas gracias


Código:
function getNoticias(url){
	$.post(url, function(data) {
		//obtenemos las noticias
		var txt = '';
		
		for(var i=0; i < data.length; i++){
			
			txt += 'Noticia' + data[i].id + '<br />';
			txt += data[i].title + '<br />';
			txt += data[i].date + '<br />';
			txt += data[i].order + '<br />';
			txt += data[i].image + '<br />';
			txt += '<pre>' + data[i].body + '</pre>';
			txt += '<br /><br />';
			
		}
	
		$('#result').html(txt);
		
	}, 'json');
}

$(document).ready(function() {
	//OBTENEMOS LA SESSION ID
	
	var fecha = new Date();
	var start = fecha.getDay() + '-' + (fecha.getMonth() + 1) + '-' + fecha.getFullYear();
	var end = fecha.getDay() + '-' + (fecha.getMonth() + 1) + '-' + (fecha.getFullYear() + 1);
	
	
	var urlSession = 'http://vita10.padelclick.com/api/newsession?apikey=YBrjfOdHb2JxxJax0NEW63rxyYwrO2WHxY2JWdpYmLYWM3zX842Nxu6rdCtG20upR9KM8hboQM6tF7ChU38h1Q';
	
	var urlNoticias = 'http://vita10.padelclick.com/api/news?start=6-8-2012&end=8-12-2100';
	urlNoticias += '&idsession=2dB8YZ9zR8fLBu5QozmBxjDBN3nthJgZX';
	
	$.post(urlSession, function(data) {

		//añadimos la sessionID a la url de las noticias
		urlNoticias += '&idsession=' + data.sessionID;
		alert(urlNoticias += '&idsession=' + data.sessionID);
		//ejecutamos la funcion que obtiene las noticias
		getNoticias(urlNoticias);
	
	}, 'json');

});

Última edición por dzirpeld; 09/01/2013 a las 01:22