G
G
Ganesha6042015-09-23 02:01:04
JavaScript
Ganesha604, 2015-09-23 02:01:04

Pass JS variable about Vkontakte user ID to php. Where is the mistake?

There is a test file, index11.php. It has this code:

<script src="//vk.com/js/api/openapi.js" type="text/javascript"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<script>
window.onload = (function() {
    VK.init({
          apiId: 5079578 // id приложения в вк
        });
    function authInfo(response) 
    {
      if (response.session)
      {
        document.getElementById('id').innerHTML = + response.session.mid;
        //Тут шлем ajax-запрос, JQUERY вариант
        $.post("/index11.php",{ ID: response.session.mid } );
      } 
      else 
      {
        document.getElementById('id').innerHTML = 'Вы не авторизованы вконтакте.';
      }
    }
    VK.Auth.getLoginStatus(authInfo);
});
</script>


Next, I catch the variable (in the same file, index11.php) like this
<?php
$vkidid = ($_POST['ID']);
echo $vkidid;
?>


Please answer:
1. Am I correct that I specify the same file as the php script that is used, or is it required to catch it in another one, for example, index12.php?

2. Do I love the variable correctly at all?)

While it does not give me anything (blank page)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly Inchin ☢, 2015-09-23
@In4in

1. Am I right that I specify the same file as the php script that is used, or is it required to catch it in another one, for example, index12.php?
You already see it. If you are talking about whether it will work , then yes.
Debage
Generally correct. But you develop bracket addiction, you need to do something about it.
...

G
Ganesha604, 2015-09-23
@Ganesha604

As far as I could figure out, it doesn't send a request to /index12.php.
For example, if I remove all the code and put the test code in index11.php:

$.post(
  "/index12.php",
  {
    test: "VK"
  },
  onAjaxSuccess
);
 
function onAjaxSuccess(data)
{
  alert(data);
}

And in the handler (index12.php) I specify:
<?php
  echo "ID = ".$_POST['test'];
?>

Then he returns. Please tell me where is the mistake

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question