Javascript Ajax请求表示已成功提交数据,但php没有响应
我正在为typo3开发一个facebook登录typo3插件。我使用以下代码向php页面发送请求Javascript Ajax请求表示已成功提交数据,但php没有响应,javascript,php,jquery,ajax,facebook,Javascript,Php,Jquery,Ajax,Facebook,我正在为typo3开发一个facebook登录typo3插件。我使用以下代码向php页面发送请求 FB.getLoginStatus(function(response) { if (response.status === 'connected') { console.log(JSON.stringify(response)); jQuery.ajax({ url : "/index.php?id=379",
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网站没有回应“得到它”###测试器是前端的标记。获取的文本应显示在前端:
function main($content, $conf) {
$data = $_POST['data'] or $_REQUEST['data'];
$markerArray['###TESTER###'] = '';
if(!empty($data)) {
$markerArray['###TESTER###'] = "got it";
}
PHP代码嵌入到主函数中,除非在PHP页面中调用主函数,否则不会运行主函数
另一个问题是,在AJAX请求中,您没有设置以下POST变量:“accessToken”、“userId”,但在您调用的PHP页面中没有您要查找的“data”变量。您的PHP代码嵌入到主函数中,除非在PHP页面中调用主函数,否则不会运行主函数
另一个问题是,在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: ''});
谢谢你的回复。我想出了另一个办法。我使用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: ''});
您是否在该函数中输出ajax提交页面?从您提供的代码中,没有返回任何内容。您是否在该函数中输出ajax提交页面?从提供的代码中,您不知道这是问题所在,因此不会返回任何内容。