Answer the question
In order to leave comments, you need to log in
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>
<?php
$vkidid = ($_POST['ID']);
echo $vkidid;
?>
Answer the question
In order to leave comments, you need to log in
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.
...
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);
}
<?php
echo "ID = ".$_POST['test'];
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question