Thinkphp envío de formulario ajax
lt;headgt;
lt;script?type="text/javascript"?src="__PUBLIC__/js/jquery-1.7.1.min.js "gt;lt;/scriptgt;
lt;script?type="text/javascript"gt; $(función(){
$('entrada: botón'). hacer clic(función(){ var?$título=$('entrada[ nombre="título"]').val(); var?$mensaje=$('entrada[ nombre="mensaje"]').val( ); $mess=$('#mess'); $.getJSON('__URL__/add', {título: $título, mensaje: $mensaje}, función(json){
/alert( json); return?false;
if(json.status==1){ $mess.slideDown(3000, function(){
$mess.css('display' , 'bloque');? }).html('El título es ' json.data.title 'El mensaje es ' json.data.message);?
}else{ $mess.slideDown(3000, function(){
$mess.css('display', 'block');? }).html('Error al agregar mensaje, verifíquelo');?
} });
})? })
lt;/scriptgt;
lt;/headgt;
lt;bodygt;
lt;div?style="display:none;?color:red;"?id="mess"gt;lt;/divgt;
lt;form?action= ""?method="get"gt; Título:lt;input?type="text"?name="title"?/gt;lt;br?/gt; Mensaje:lt;input?type="text"? name="mensaje"?/gt;lt;br?/gt;
lt;input?type="botón"?value="enviar"?/gt;
lt ;/formgt;
lt;/bodygt;
lt;/htmlgt;
Lo anterior es el código anterior
MessageAction. class El código de la página .php es el siguiente:
lt;?php
class?MessageAction?extends?Action{ function?index(){
$ this-gt; display();? } function?add(){
//ajaxReturn(datos,'mensaje de alerta',estado)?
$m=M(' mensaje');
if($m-gt;add($_GET)){ $this-gt;ajaxReturn($_GET,'Añadir mensaje correctamente',1);
}else{ $this-gt .ajaxReturn(0,'Error al agregar mensaje',0);?
} }
} gt;