0

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.

2 Answers 2

1

as @Joel_Blum said, and also do this: you should add return false; at the end of the body of the function on('click',function(){ ... to prevent reloading the page.

Sign up to request clarification or add additional context in comments.

Comments

0

try this

url :  '<?php echo site_url("accounts/update_user_account_ajax")?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.