我想將會話變量存儲到普通變量並使用ajax我需要將值發送到下一頁,但它給了我ajax代碼中的錯誤。下面是我的代碼如何將會話變量發送到下一頁?
的index.php
$OTP = $_SESSION['smsgatewaycenterotp'];
echo $OTP;
的Ajax功能
<script type="text/javascript">
$('#btnonOtp').click(function()
{
var otp = $('$OTP').val();
$.ajax({
url: "sms.php",
method:'POST',
data:
{mobile: $('#mobile').val(),
otp:otp},
success: function(msg)
{
alert('OTP Sent');
console.log(msg);
}
});
});
</script>
Sms.php
<?php
include 'send.php';
session_start();
var_dump($_POST);
console.log(msg);
echo $_POST['mobile'];
$OTP = $_POST['otp'];
$number = $_POST['mobile'];
//$text = 'Hi There, how are you?';
$sms_api_result = sms_Send($number, 'Please do not share the one time password with anyone. Your One Time password is: '.$OTP,$debug);
?>
能任何人都能幫我解決這個問題。
它給你什麼錯誤? –
在你的php文件中你使用過'session_start();'? – Beginner
那麼,你在哪裏引用ajax中的'$ OPT'? – Andy