I have these text inputs in which they are preloaded with the user information on document load. My input html is as below
<div class="control-group">
<label class="control-label" for="first_name">First Name</label>
<div class="controls">
<input type="text" class="account" id="first_name" placeholder="First Name">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">Email</label>
<div class="controls">
<input type="text" class="account" id="inputEmail" placeholder="Email">
</div>
</div>
My preload is like this in jquery, in which it does a $.post to a php function. This works fine as the input elements are filled correctly.
function loadUserInfo()
{
$.post('../accounts/load_user_info_ajax', null, function(data) {
console.log(data.message);//Test to return user id
var user = data.message;
$('#inputEmail').val(user.email);
$('#first_name').val(user.name);
}, 'json');
}
However there is a update btn in which when I click on, it sends a $.post to another function. The jquery is as below
$('.update').on('click',function(){
var type = $(this).attr('id');
if(type == "account")
{
postvars = {
name:$('#first_name').val(),
email : $('#inputEmail').val(),
};
url = '../accounts/update_user_account_ajax';
}
$.post(url, postvars, function(data) {
console.log(data);//Test to return user id
alert(data.message);
var user = data.message;
}, 'json');
});
For a start I just return
function update_user_account_ajax()
{
if ($this->input->is_ajax_request()) {
echo json_encode("test");
}else {
show_404();
}
}
But nothing happens and I cannot see anything from chrome debugger network as well. The page refreshes as well and appends a ? to the ur. Thanks in advance for the help. I am using codeigniter for my php.