[eluser]InterMedio[/eluser]
Hello everybody!
I need display value of "input" field, where I use jQuery and Ajax.
I has view viewprofileedit.php
Code:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Here you can edit your profile</title>
[removed][removed]
[removed][removed]
[removed]
$(document).ready(function() {
$('#save').click(function() {
var item = $('#item').val();
$.post("/profile/edit", { 'item' : item },
function(data){
alert(data.result);
}, "json");
});
});
[removed]
</head>
<body>
<form id="items">
<p>
<input type="text" name="item" id="item" />
</p>
<p>
<input type="submit" name="save" id="save" value="Save Item" />
</p>
</form>
</body>
</html>
and controller, where I use method edit(), which should be add string "From the controller " to value of element with id="item".
Code:
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Profile extends CI_Controller{
function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->library('my_auth');
}
function index(){
if (!$this->my_auth->is_logged_in()) {
redirect('/auth/login/');
} else {
$this->load->view('viewprofile');
redirect('/begin');
}
}
function edit() {
if (!$this->my_auth->is_logged_in()) {
redirect('/auth/login/');
} else {
$item = "From the Controller: ".trim($this->input->post('item'));
$array = array('result' => $item);
echo json_encode($array);
}
}
function editor() {
if (!$this->my_auth->is_logged_in()) {
redirect('/auth/login/');
} else {
$this->load->view('viewprofileedit');
}
}
}
But when I go to
http://site.com/profile/editor and enter data into form and press button, I watch next:
{"result":""}
But I must get next alert message: "From the Controller: value_of_item_field"
What is my problem?
Thanks all.