javascript - 如何通过json_encode重定向php页面
问题描述
我有两个文件。1 是 controller.php 和 2nd verification.js 一旦验证功能成功执行,我需要重定向。
Controller.php
<?php
session_start();
error_reporting(E_ALL & ~ E_NOTICE);
require ('textlocal.class.php');
class Controller
{
function __construct() {
$this->processMobileVerification();
}
function processMobileVerification()
{
switch ($_POST["action"]) {
case "send_otp":
$mobile_number = $_POST['mobile_number'];
$apiKey = urlencode('aphfkjshjkskshfkjshfksjhfksjdh');
$Textlocal = new Textlocal(false, false, $apiKey);
$numbers = array(
$mobile_number
);
$sender = 'TXTLCL'; //urlencode('TXTLCL')
echo $otp = rand(100000, 999999);
$_SESSION['session_otp'] = $otp;
$message = "Your One Time Password is " . $otp;
try{
$response = $Textlocal->sendSms($numbers, $message, $sender);
require_once ("verification-form.php");
exit();
}catch(Exception $e){
die('Error: '.$e->getMessage());
}
break;
case "verify_otp":
$otp = $_POST['otp'];
ob_start();
if ($otp == $_SESSION['session_otp']) {
//unset($_SESSION['session_otp']);
echo json_encode(array("type"=>"success", "message"=>"Your mobile number is verified!"));
} else {
echo json_encode(array("type"=>"error", "message"=>"Mobile number verification failed"));
}
break;
}
}
}
$controller = new Controller();
?>
第二个文件verification.js
function sendOTP() {
$(".error").html("").hide();
var number = $("#mobile").val();
if (number.length == 10 && number != null) {
var input = {
"mobile_number" : number,
"action" : "send_otp"
};
$.ajax({
url : 'controller.php',
type : 'POST',
data : input,
success : function(response) {
$(".container").html(response);
}
});
} else {
$(".error").html('Please enter a valid number!')
$(".error").show();
}
}
function verifyOTP() {
$(".error").html("").hide();
$(".success").html("").hide();
var otp = $("#mobileOtp").val();
var input = {
"otp" : otp,
"action" : "verify_otp"
};
if (otp.length == 6 && otp != null) {
$.ajax({
url : 'controller.php',
type : 'POST',
dataType : "json",
data : input,
success : function(response) {
$("." + response.type).html(response.message)
$("." + response.type).show();
},
error : function() {
alert("ss");
}
});
} else {
$(".error").html('You have entered wrong OTP.')
$(".error").show();
}
}
我不确定,我需要在哪里放置重定向代码。我想要,一旦我的手机号码得到验证。这应该被重定向到abc.php
页面。
提前谢谢,帮我解决这个问题。
解决方案
推荐阅读
- python - Pandas:使用 python map() 意外输出数据类型
- angular - angular-file-uploader 附加参数
- xamarin.forms - 如何为 Azure AD 形成正确的租户 URL
- sql-server - SQL Server - 表中每个连续条目之间的差异总和
- javascript - ASP.NET MVC 和 WebAPI 使用数据库表插入和检索记录
- angular - EventEmitter 类的清晰概念
- excel - 根据 Excel 中不同范围内的值查找系列的最大值
- sql - SQL Server 中的日期计数
- batch-file - 通过 Jenkins 中的批处理脚本上传 QAV 失败
- python - 字典中的结构系列(python)