Saturday, 7 September 2019

Type of Ajax calling

Ajax calling with manual passing the data

<form id='user_info'>
    <input type='text' id='user_id' value='40'>
    <input type='text' id='project_id' value='402'>
<a href='javascript:void(0)' onclick='get_user_info()'></a>
</form>

 
<script type='text/javascript'>
function get_user_info(){
    user_id = $('#user_id').val();
    project_id = $('#project_id').val();
    $.ajax({
    url: '/create_user_information',
    data: {user_id: user_id, project_id: project_id},
    dataType: 'script',
    type: 'POST',
    success: function (data) {
    }
  });
}

</script>


Ajax calling with serialize method

<form id='user_info'>
    <input type='text' id='user_id' value='40'>
     <input type='text' id='project_id' value='402'>
<a href='javascript:void(0)' onclick='get_user_info()'></a>
</form>


<script type='text/javascript'>
function get_user_info(){
    user_id = $('#user_id').val();
    project_id = $('#project_id').val();
    $.ajax({
    url: $('#user_info').attr('action'),
    data: $('#user_info').serialize(),
    dataType: 'script',
    type: 'POST',
    success: function (data) {
    }
  });
}

</script>

No comments:

Post a Comment

Interactor in Rails

What is interactor? Interactor provides a common interface for performing complex user interactions An interactor is a simple, sin...