[英]Ajax request said successful submitted data but php does not respond
我正在为typo3开发一个Facebook登录typo3插件。 我使用以下代码将请求发送到php页面。
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
console.log(JSON.stringify(response));
jQuery.ajax({
url : "/index.php?id=379",
type: "POST",
data : "{accessToken:" + "'"+ response.authResponse.accessToken + "', userID:" + "'" + response.authResponse.userID + "'}",
success: function(data, textStatus, jqXHR)
{
console.log("Data submitted");
console.log(data);
},
error: function (jqXHR, textStatus, errorThrown)
{
console.log("Data not submitted");
}
});
}
});
我收到“已提交数据”作为响应,但是我的php网站却没有“得到它”响应。 ### TESTER ###是前端的标记。 收到的文本应显示在前端:
function main($content, $conf) {
$data = $_POST['data'] or $_REQUEST['data'];
$markerArray['###TESTER###'] = '';
if(!empty($data)) {
$markerArray['###TESTER###'] = "got it";
}
您的PHP代码嵌入在main函数中,除非在PHP页面中调用main函数,否则它将不会运行。
另一个问题是,在AJAX请求中,您没有设置以下POST变量:“ accessToken”,“ userId”,但是在要调用的PHP页面中没有要查找的“ data”变量。
感谢您的答复。 我想出了另一种方式。 我使用windows.location在URL中提交accessToken。 不是最好的方法,但是它可以工作。
FB.login(function(response) {
if (response.authResponse) {
var access_token = FB.getAuthResponse()['accessToken'];
var userID = FB.getAuthResponse()['userID'];
FB.api('/me', function(response) {
console.log('Erfolgreiche Anmeldung für: ' + response.name);
document.getElementById('status').innerHTML =
'Danke für die Anmeldung, ' + response.name + '!';
var location = "/index.php?id=379&accessToken=" + access_token + "&userID=" + userID;
console.log(location);
window.location = location;
});
} else {
console.log('User cancelled login or did not fully authorize.');
}
}, {scope: ''});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.