Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

wdc_black_

Função só funciona no Internet Explorer

Recommended Posts

Eai galera, to com 1 código aqui para editar um texto ao clica no campo dele, mas só está funcionando no Internet explorer, queria a ajuda de vocês pois não tenho quase nada de conhecimento em ajax ;)

 

index.php

<!doctype html public "-//W3C//DTD HTML 4.0 //EN">

<html>

<head>
<title>Ajax Inline Edit </title>

<script type="text/javascript" src="jquery-1.2.6.min.js"></script>
<link href="dependencies/screen.css" type="text/css" rel="stylesheet" />

<script type="text/javascript">
// <![CDATA[	

$(document).ready(function(){	

	$('#save').hide();
	$('#cancel').hide();

	$('#editPanel').click(function() {  

		$('#editPanel').attr('contentEditable', true);
		$('#editPanel').focus();

		$('#save').fadeIn();
		$('#cancel').fadeIn();

	});

	$('#save').click(function(){    

		var text = $('#editPanel').html();
		//alert(text);
		$("#Mesg").html('<img  src="imgs/load.gif" id="loader" />');

		 $.ajax({
                type: "POST",
                url: "update.php",
                data: "text=" + text,
			 success: function(){


			 $("#Mesg").html('Text Updated !');				 
			 $('#editPanel').attr('contentEditable', false);

			 $('#save').fadeOut();
			 $('#cancel').fadeOut();				 
			}
		 });
	 });

	 $('#cancel').click(function(){    

	 	$('#editPanel').attr('contentEditable', false);

		 $('#save').fadeOut();
		 $('#cancel').fadeOut();
	 });

});

// ]]>
</script>

</head>
<body>

<div align="center">

	<h1>
		Ajax Inline Edit 
	</h1>

	<br clear="all" />

	<div id="wrap">

		<div id="Mesg"> </div>

		<?php  include_once('update.php');?>
		<a href="#" id="save" class="save">Save</a>
		<a href="#" id="cancel" class="cancel">Cancel</a>
		<br clear="all" />
	</div>


</div>
</body>
</html>

 

update.php

	<?php
include('dbcon.php');
// ini_set('display_errors', true); 	mostrar todos erros php
// error_reporting(E_ALL); 				mostrar todos erros php

function checkValues($value)
{
	$value = trim($value);
	if (get_magic_quotes_gpc()) {
		$value = stripslashes($value);
	}
	$value = strtr($value,array_flip(get_html_translation_table(HTML_ENTITIES)));
	$value = strip_tags($value);
	$value = mysql_real_escape_string($value);
	$value = htmlspecialchars ($value);
	return $value;
}	

       if( isset( $_POST['text'] ) )
       {
       $text = checkValues($_POST['text']);
	mysql_query("update edit_able set text = '".$text."' where id = 1");

	$result = mysql_query("SELECT * from edit_able where id = 1") or die( mysql_error() );
}
else
{	
	$result = mysql_query("SELECT * from edit_able where id = 1") or die( mysql_error() );
}

while ($row = mysql_fetch_array($result))
{?>
	<textarea id="editPanel" name="text" style="width:350px" rows="10">
	<?php echo $row['text'];?>
	</textarea>
	<?php
}?>

 

dbcon.php

<?php

$link = mysql_connect('localhost', 'root', '');
mysql_select_db('inline',$link);

?>

 

obrigado

Compartilhar este post


Link para o post
Compartilhar em outros sites

se o seu editPanel é um textarea, então você não precisa do atributo: contentEditable

 

só vi ele de 'problemático'.

aperte Ctrl + Shift + J no Firefox, e acompanhe o log de erros. Tente corrigir oque aparecer.

Compartilhar este post


Link para o post
Compartilhar em outros sites

fiz esse procedimento mas n acorreu nenhum erro no console, e tambem tirei o contentEditable, mas continua n gravando no banco.

 

só funciona no internet explorer =/

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.