Javascript Ajax调用不';我不回答
在登录页面中,我包含一个php文件,如下所示 JSJavascript Ajax调用不';我不回答,javascript,jquery,ajax,Javascript,Jquery,Ajax,在登录页面中,我包含一个php文件,如下所示 JS <script> var APP_URL = '<?= APP_URL?>'; function migrate(value){ if(value==1) { $j.ajax({ type: 'POST', url: APP_URL+"corporate/secApi", data : {migration:1},
<script>
var APP_URL = '<?= APP_URL?>';
function migrate(value){
if(value==1) {
$j.ajax({
type: 'POST',
url: APP_URL+"corporate/secApi",
data : {migration:1},
success: function (rs) {
console.log(rs);
alert("Migration Completed!\nEnjoy the new Goal feature");
$j("#fulldiv").remove();
},
failure: function () {
alert("call to secApi failed!");
}
});
}else{
$j("#fulldiv").remove();
}
}
</script>
调用完成后,我可以看到控件进入secApi.php,日志中没有任何内容。它以前工作过,但只有在我回显'd 1而不是true时才起作用。在ajax调用的成功部分,我检查了(rs==1)dosomething,但现在甚至都不起作用。我就是找不到原因
有什么建议吗?我做错了什么吗?为了在客户端获得该值,应该在PHP中使用echo而不是返回
<?php
$response = false;
if(isset($_POST['migration'])){
if($_POST['migration']==1) {
$apiMgr = new SecureAPIClient((int)$_SESSION['id_user'], (int)$_SESSION['id_user_sub'], $ALLOWED_RESOURCES);
$response = $apiMgr->migrateAccount($_SESSION['id_user']);
}
}
echo $response;
?>
为什么要为所有内容设置ID?为什么不使用类呢?此外,同一页面中不应有多个具有相同ID的元素。failure
这是什么???有更多的逻辑,它会回显一些其他值。我在特定条件下执行这段代码。这就是为什么我在回音1后回来了。这是否意味着当我想停止要执行的页面的其余部分时,应该使用exit?
if(isset($_POST['migration'])){
$response = false;
if($_POST['migration']==1) {
$apiMgr = new SecureAPIClient((int)$_SESSION['id_user'], (int)$_SESSION['id_user_sub'], $ALLOWED_RESOURCES);
$response = $apiMgr->migrateAccount($_SESSION['id_user']);
if($response==true)
echo 1;
return;
}
}
<?php
$response = false;
if(isset($_POST['migration'])){
if($_POST['migration']==1) {
$apiMgr = new SecureAPIClient((int)$_SESSION['id_user'], (int)$_SESSION['id_user_sub'], $ALLOWED_RESOURCES);
$response = $apiMgr->migrateAccount($_SESSION['id_user']);
}
}
echo $response;
?>