[eluser]finord[/eluser]
Hello, i have problem with this script. I try to send data usng ajax( with jQuery)
, and insert to bd (mysql).
But i dont know why dont work ajax, the go directly to the controller url.
Controller:
Code:
<?
class fadd extends Controller
{
function sendt()
{
$this->load->helper('form');
$this->load->view('form');
}
}
?>
Model:
Code:
<?
class add extends Controller
{
function add()
{
parent::Controller();
}
function index() {
}
function nadd()
{
$titulo = $_POST['titulo'];
$texto = $_POST['noticia'];
$fecha = $_POST['fecha'];
/*$cat = $_POST['categoria'];
*/
$ct=count($titulo);
$cx=count($texto);
$cf=count($fecha);
$this->load->database();
$data = array(
'titulo' => $titulo ,
'noticia' => $texto,
'fecha' => $fecha,
/*'cat' => $cat
*/);
if( $this->db->insert('news', $data) == TRUE) {
$this->load->view('addview');
}
else {
echo "No se ha podido realizar la entrada, compruebe los parametros y la configuracion";
}
// Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date')
}
}
?>
View:
Code:
<?
$this->load->helper('url');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head profile="http://gmpg.org/xfn/11">
<title>Saiend</title><link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
>script type="text/javascript" src='<?=base_url()?>js/jquery.js'>>/script>
>script>
function tabular(e,obj) {
tecla=(document.all) ? e.keyCode : e.which;
if(tecla!=13) return;
frm=obj.form;
for(i=0;i<frm.elements.length;i++)
if(frm.elements[i]==obj) {
if (i==frm.elements.length-1) i=-1;
break }
frm.elements[i+1].focus();
return false;
}
>/script>
<link rel="stylesheet" href='<?=base_url()?>style/reset.css' type="text/css" media="screen, projection" />
<link rel="stylesheet" href='<?=base_url()?>tyle/default.css' type="text/css" media="screen, projection" />
<link rel="stylesheet" href='<?=base_url()?>style/styling.css' type="text/css" media="screen, projection" />
<link rel="stylesheet" href='<?=base_url()?>style/print.css' type="text/css" media="screen, projection" />
>script>
function post() {
$.post("<?=base_url()?>add/nadd",{ titulo:$("#titulo").val() , fecha:$("#fecha").val() ,
noticia:$("#noticia").val() },function(response) {
$("#update").html(response);
});
}
>/script>
</head>
<body class="fullwidth">
<div id="container">
<div id="header">
<div id="header-in">
</div> <!-- end #header-in -->
</div> <!-- end #header -->
<div id="content-wrap" class="clear">
<div class="main">
<div class="box">
<h1>Sign in</h1>
<p>Do you have an account? Sign in!</p>
<form method="post" action="<?=base_url()?>/add/nadd" id="nvm">
<label><span>Titulo</span>
<input type="text"name="titulo" id="titulo" class="input-text">
</label>
<label><span>Fecha</span>
<input type="text"name="fecha" id="fecha" class="input-text">
<label><span>Noticia:</span>
<textarea rows="10" cols="70" class="fta" name="noticia" id="noticia"></textarea>
</label>
<br>
<div class="spacer"><input type="submit" >
</label>
</form></div>
<div class="spacer">
Lost your data? <a href="#">Get your password</a><br/>
New User? <a href="#">Sign up</a>
</div>
</div>
<div id="update" style="border: 1px dotted red;"></div>
</div>
</div>
<!-- end #content-wrap -->
<!-- a�adir otros div, debajo de 1up-->
<div class="clear"></div>
<!-- end #footer -->
</div>
<!-- end div#container -->
<!-- end of content, starting some javascript... -->
<!-- common functions -->
</body>
</ul>
</html>
If anyone can help me i think the problem is on the javascript code, but i test with other php code("normal" php code, NO with Framework or something)
Thanks