Ver Mensaje Individual
  #1 (permalink)  
Antiguo 29/04/2012, 21:50
JPZamora
 
Fecha de Ingreso: mayo-2009
Ubicación: Mérida, Yucatán
Mensajes: 68
Antigüedad: 15 años
Puntos: 3
Formulario con Ajax y JSON

Estoy haciendo el intento de crear un formulario en el que envies un comentario, al finalizar el envio te confirmara dandote de resultado tu mismo comentario con nombre y codigo de comentario a traves de un responde en JSON.

Este es mi codigo, segun he leido asi debe de ir, no se si tenga algun error.

Código HTML:
<!DOCTYPE html>
<html>
    <head>
		<meta name="viewport" content="width=device-width, initial-scale=1"> 
		<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />       
		<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
		<script src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
        <script type="text/javascript" language="javascript">
        function sendForm(nombre,mensaje){
        $.ajax({
        	data: "name=" + nombre+ "&msg=" + mensaje,
        	dataType: "json",
        	type: "GET",
    		url: "http://jupazave.com/temporal/api.php",
    		success: function(dato) {
		                   var data_as_json = dato.data;
		                   var cc = dato."Comment Code";
		                   	$("#status").append("Mensaje Enviado (" + html(data_as_json.cc) + ") <br/> Nombre:" +  html(data_as_json.Name) + "<br/> Mensaje:" + html(data_as_json.Message) + "<br/>");

	                   }
    		
		});

		}
		
		</script>
    </head>
    <body>
	<div data-role="page">
	    <div data-role="header">
	         <h1>Forms</h1>
	    </div>
	    <div data-role="content">
			<form action='javascript:sendForm($("#numero").val(),$("#mensaje").val())' method="post">
				<div data-role="fieldcontain">
					<label for="nombre">Nombre:</label>
					<input type="text" name="nombre" id="nombre" />
				</div>

				<div data-role="fieldcontain">
					<label for="mensaje">Mensaje:</label>
					<textarea name="mensaje" id="mensaje"></textarea>
				</div>
				<p> <input type="submit" value="Send Messages"></p>
			</form>
			<br/>
			<div id="status"></div>
	    </div>
	    <div data-role="footer">
	         <h4>2012</h4>
	    </div>
	</div>

    </body>
</html> 
y el JSON de api.php imprime (valores de ejemplo):


Código:
{"data":
	{"Comment Code":"15",
	"Name":"Juan",
	"Message":"Hola a todos"},
"progress":"DONE"}
Gracias de antemano.