Foros del Web » Programando para Internet » PHP »

Refrescar div pero sin url

Estas en el tema de Refrescar div pero sin url en el foro de PHP en Foros del Web. Hola, he visto algunos refresh en ajax, que refrescan el div, pero tienes que darle una url, el caso es, que yo no tengo en ...
  #1 (permalink)  
Antiguo 04/10/2008, 03:44
 
Fecha de Ingreso: mayo-2007
Mensajes: 68
Antigüedad: 17 años
Puntos: 0
Refrescar div pero sin url

Hola, he visto algunos refresh en ajax, que refrescan el div, pero tienes que darle una url, el caso es, que yo no tengo en el div, ninguna url, si no que tengo un código php y javascript, la cuestión es, que tengo hecho un sistema de favoritos por cookie, cuando un usuario añade el favorito (cookie), para refrescar el div donde se muestra la cookie, hay que volver a cargar la página, y quiero hacer que se refresque solo el div, pero, como dije anteriormente, que no haya que tener ninguna url para refrescar, si no el mismo div, pero modificado.

Espero haberme explicado bien. Gracias.
  #2 (permalink)  
Antiguo 04/10/2008, 05:53
Avatar de geq
geq
 
Fecha de Ingreso: agosto-2006
Ubicación: Rosario
Mensajes: 655
Antigüedad: 17 años, 8 meses
Puntos: 22
Respuesta: Refrescar div pero sin url

Pero para poder hacer eso tiene que haber algo que pueda volver a procesar ese código php. Una vez que php se ejecutó y puso el contenido de un div no hay forma de volver a ejecutarlo si no es volviendo a cargar la página, no es como javascript que se ejecuta en el navegador y pudés hacerlo correr como quieras.

Por eso lo que tenés que hacer es tener esa url que decís. Crear un nuevo script con ese código php que te genere la información que va en el div.

Entonces para actualizarlo simplemente vuelves a ejecutar ese script y cargas, todo con javascript o ajax, la respuesta en el div.

Saludos.
  #3 (permalink)  
Antiguo 04/10/2008, 08:35
 
Fecha de Ingreso: mayo-2007
Mensajes: 68
Antigüedad: 17 años
Puntos: 0
Mensaje Respuesta: Refrescar div pero sin url

Hola, el contenido del div es este:

Código:
<div onclick="expandcontent('sc1')" style="z-index: 4;font-family: Arial;font-size: 14px;font-weight: bold;text-align: center;background-image: url(http://www.addictools.com/images/fav.gif);background-repeat: no-repeat; left: 0px; top: 0px;cursor: hand; cursor:pointer;position: absolute;margin-top: 60px;width: 100px; height: 29px;"><div style="margin-top: 4px;">Favorites</div></div>
<div  style="font-family: Arial;font-size: 13px;left: 0px; top: 0px;position: absolute;margin-top: 86px;width: 150px;border-color: #3da40a;
border-style: solid;
border-width: 1px;background-color: #efefef;" id="sc1" class="switchcontent"><?php
if( isset( $_COOKIE['ako'] ) ) {
        echo "<div style=\"margin-top: 5px;\"><img src=\"http://utility-tools.addictools.com/cog.png\" title=\"This favorite is a utility tool\" alt=\"This favorite is a utility tool\" />   <a href=\"http://scrollbar-creator.addictools.com/\">$_COOKIE[ako]</a> <a href=\"#\" onclick=\"sco()\"><img style=\"margin-left: 9px;\" src=\"http://www.addictools.com/images/close.png\" title=\"Delete\" alt=\"Delete\" /></a></div>";
        } else {
       echo "";
       }
      if( isset( $_COOKIE['pop'] ) ) {
        echo " <a href=\"http://popups-creator.addictools.com\"><div style=\"margin-top: 5px;margin-bottom: 5px;\"><img src=\"http://utility-tools.addictools.com/cog.png\" title=\"This favorite is a utility tool\" alt=\"This favorite is a utility tool\" />  $_COOKIE[pop]</a> <a href=\"#\" onclick=\"Delete_Cookie('pop', '/', 'addictools.com')
 alert('The favorite called Popups creator has been removed');\"><img style=\"margin-left: 17px;\" src=\"http://www.addictools.com/images/close.png\" title=\"Delete\" alt=\"Delete\" /></a></div>";
        } else {
       echo "";
       }
          if( isset( $_COOKIE['byte'] ) ) {
        echo "<div style=\"margin-top: 5px;margin-bottom: 5px;\"><img src=\"http://utility-tools.addictools.com/cog.png\" title=\"This favorite is a utility tool\" alt=\"This favorite is a utility tool\" />   <a href=\"http://byte-converter.addictools.com\">$_COOKIE[byte]</a> <a href=\"#\" onclick=\"Delete_Cookie('byte', '/', 'addictools.com')
 alert('The favorite called Byte converter has been removed');\"><img style=\"margin-left: 21px;\" src=\"http://www.addictools.com/images/close.png\" title=\"Delete\" alt=\"Delete\" /></a></div>";
        } else {
       echo "";
       }
          if( isset( $_COOKIE['byte'] ) OR  isset( $_COOKIE['pop'] ) OR isset( $_COOKIE['ako'] )) {

        echo "<hr><a href=\"#\" onclick=\"deleteall()\"><div style=\"cursor: hand; cursor:pointer;text-align: center;margin-bottom: 5px;\">Delete all</div></a>";
        }
   if( !isset( $_COOKIE['byte'] ) &&  !isset( $_COOKIE['pop'] ) && !isset( $_COOKIE['ako'] )) {
   
   echo "<div style=\"margin-top: 5px;margin-bottom: 5px;\">You don't have favorites.</div>";
}        
?></div>
</div>
Y claro, este contenido, llama a un trozo de archivo javascript, este:


Código:
function Set_Cookie( name, value, expires, path, domain, secure ) 
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct 
expires time, the current script below will set 
it for x number of days, to make it for hours, 
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}
function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

// this fixes an issue with the old method, ambiguous values 
// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}	
function primerizo()
{
Set_Cookie( 'ako', 'Scrollbar Creator', '3000', '/', 'addictools.com', '' )
if ( Get_Cookie( 'ako' ) ) alert('You just added the link to the menu of favorites. Now you will have a link in the menu on the left side, where you can watch your favorite links, quickly.');
     document.getElementById("sc1").innerHTML = "Refresh the page for see the new favorites."
}
function pop()
{
Set_Cookie( 'pop', 'Popups Creator', '3000', '/', 'addictools.com', '' )
if ( Get_Cookie( 'pop' ) ) alert('You just added the link to the menu of favorites. Now you will have a link in the menu on the left side, where you can watch your favorite links, quickly.');
     document.getElementById("sc1").innerHTML = "Refresh the page for see the new favorites."

}
function byte()
{
Set_Cookie( 'byte', 'Byte Converter', '3000', '/', 'addictools.com', '' )
if ( Get_Cookie( 'byte' ) ) alert('You just added the link to the menu of favorites. Now you will have a link in the menu on the left side, where you can watch your favorite links, quickly.');
}

function sco()
{

Delete_Cookie('ako', '/', 'addictools.com')
 alert('The favorites are been removed');
      document.getElementById("sc1").innerHTML = "<div style=\"margin-top: 5px;margin-bottom: 5px;\">Refresh the page for see the changes.</div>"

 }
function deleteall()
{

if (confirm('Are you sure to delete ALL the favorites?')) {
Delete_Cookie('ako', '/', 'addictools.com')

Delete_Cookie('pop', '/', 'addictools.com')


Delete_Cookie('byte', '/', 'addictools.com')
 alert('All the favorites are been removed');
       document.getElementById("sc1").innerHTML = "<div style=\"margin-top: 5px;margin-bottom: 5px;\">Refresh the page for see the changes.</div>"
 } else {
 alert('Ok, the favorites have not been eliminated');

}
}

// remember, these are the possible parameters for Set_Cookie:
// name, value, expires, path, domain, secure
// and these are the parameters for Delete_Cookie:
// name, path, domain
// make sure you use the same parameters in Set and Delete Cookie.
Entonces, como lo hago?
  #4 (permalink)  
Antiguo 04/10/2008, 10:07
 
Fecha de Ingreso: mayo-2007
Mensajes: 68
Antigüedad: 17 años
Puntos: 0
Respuesta: Refrescar div pero sin url

No existe solución?

Hombre, así si me sale:

document.getElementById("div_id").innerHTML = "nuevo contenido"

Pero lo que yo quiero, no es poner un texto html en lugar del div, si no un texto php, para poner if isset cookies, y eso. Por eso ese código no me vale.

Saludos.
  #5 (permalink)  
Antiguo 04/10/2008, 11:11
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años, 1 mes
Puntos: 2534
Respuesta: Refrescar div pero sin url

no se evalúa PHP en el navegador (solo en el servidor), lo que buscas se hace fácil con ajax...

suerte!
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #6 (permalink)  
Antiguo 04/10/2008, 11:30
 
Fecha de Ingreso: mayo-2007
Mensajes: 68
Antigüedad: 17 años
Puntos: 0
Respuesta: Refrescar div pero sin url

Y como lo hago con ajax?
  #7 (permalink)  
Antiguo 04/10/2008, 15:48
Avatar de Carlojas  
Fecha de Ingreso: junio-2007
Ubicación: Shikasta
Mensajes: 1.272
Antigüedad: 16 años, 11 meses
Puntos: 49
Respuesta: Refrescar div pero sin url

Que tal Zptweb, ve al Foro de AJAX, creo te podrán orientar mejor.



Saludos.
__________________
"SELECT * FROM Mujeres WHERE situacion NOT IN ('CASADAS','CON HIJOS','ATORMENTADAS','CUASI-ENNOVIADAS') AND personalidad <> 'INTENSA'"
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 07:13.