JavaScript How to send data from view to controller in codeigniter send data from javascript to python,send data from arduino

I am new to code-igniter. In my View I added this code to enable google login in my website.

<html lang="en">
<head>
<meta name="google-signin-scope" content="profile email">
<meta name="google-signin-client_id" content="720765566138-5c6jreo4r7ma6cm0hdblj5cmjtdiruk4.apps.googleusercontent.com">
<script src="https://apis.google.com/js/platform.js" async defer>     </script>
</head>
<body>
<div class="g-signin2" data-onsuccess="onSignIn" data-onfailure="onFailure" data-theme="dark"></div>
<script>
function onFailure(msg){ console.log(msg); }
function onSignIn(googleUser) {
    console.log("onSignIn");
    var profile = googleUser.getBasicProfile();
    var user_name = profile.getName();
    var id = googleUser.getAuthResponse().id;
};
</script>
</body>
</html>

How can I send the variable user_name and id to the Controller so that I can call the Model to insert the value to the database.

Answer:1

You can simply use ajax to post the information once you've gotten it (using jquery below):

<script>
    function onSignIn(googleUser)
   {
       var profile = googleUser.getBasicProfile();
       var user_name = profile.getName();
       var id = googleUser.getAuthResponse().id;
       $.ajax({
               'url': 'the/path/to/controller',
               'type': 'POST',
               'data':{'user_name': user_name, 'id':id},
               'success': function(){}, //up to you
               'error': function() // up to you
             })
    };
</script>
Answer:2

You have to make controller's action and in this you have to pass variable like this :

function test{
    $user_name = "XYZ";
    $this->load->view('view_name', $user_name);
    }

If you want to pass more than one variable then use below :

function test{
        $user_name = "XYZ";
        $data = 123;
        $this->load->view('view_name', array("user_name"=>$user_name,"data"=>$data));
    }
May this will help you :)
Answer:3

what is the difference between bootstrap.min.css and bootstrap.min.js ? Why bootstrap.min.js need to be included? <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/...

what is the difference between bootstrap.min.css and bootstrap.min.js ? Why bootstrap.min.js need to be included? <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/...

  1. what difference between bourbon and whiskey
  2. what difference between vegan and vegetarian
  3. what difference between psoriasis and eczema
  4. what difference between flu a and b
  5. what difference between ipad and ipad air
  6. what difference between republic and democracy
  7. what difference between inc and llc
  8. what difference between chromebook and laptop
  9. what difference between md and do
  10. what difference between virus and bacteria
  11. what difference between w2 and w4
  12. what difference between perfume and eau de toilette
  13. what difference between cold and flu
  14. what difference between catholic and christian
  15. what difference between diabetes 1 and 2
  16. what difference between california king and king
  17. what difference between macbook air and pro
  18. what difference between airpod 1 and 2
  19. what difference between medicare and medicaid
  20. what difference between bipolar 1 and 2

let me description the problem first. i have nav-tab and 3 tab-panes. first portfolio, second recommendation and third statistic. in tab-panes recommendation i want to put a slick.js but when i run, ...

let me description the problem first. i have nav-tab and 3 tab-panes. first portfolio, second recommendation and third statistic. in tab-panes recommendation i want to put a slick.js but when i run, ...

  1. slick inside bootstrap tab
  2. slick slider inside bootstrap tab
  3. slick slider inside bootstrap modal
  4. slick slider inside bootstrap tab not working

I was reading this example on Promise. I realized that Error constructor is not called with new operator. Why does it work, then?

I was reading this example on Promise. I realized that Error constructor is not called with new operator. Why does it work, then?

I am trying to find out if the last td of an tr was clicked. This is my HTML example: <table> <tr> <td>Foo</td> <td>Bar</td> <td&...

I am trying to find out if the last td of an tr was clicked. This is my HTML example: <table> <tr> <td>Foo</td> <td>Bar</td> <td&...

  1. check last element in list python
  2. check last element in array javascript
  3. check last element in foreach php
  4. check last element in array php
  5. check last element in foreach c#
  6. check last element in foreach java
  7. check last element of vector c++
  8. check last element in list java
  9. check last element in list c#
  10. check last element of string python
  11. check last element of array
  12. check last element in array java
  13. check last element of array swift
  14. check last element of string
  15. check last element of array js
  16. check last element in for loop java
  17. check last element in jquery
  18. check last element python
  19. check if last element in array javascript
  20. check if last element in list python