Javascript 未在live server中的页面之间传递数据
我只是在把我的网站上传到实时服务器后才遇到了这个奇怪的问题。在localhost中,我对这些没有问题 问题在于登录和注册功能。让我先谈谈登录 我键入了凭据,发现该页面在f12网络选项卡中被调用。但是该页面没有检索到任何数据!因此,我暂时搁置jquery/ajax,手动检查php页面是否返回任何数据,但仍然没有 现在,流程如下所示: 用户填写的登录表单->来自php脚本的ajax请求->来自类文件的php请求,并返回到ajax->ajax以访问管理仪表板 现在,正如我告诉您的,我排除了ajax请求,只使用php和类文件进行检查。同样,它不会从类文件返回任何内容到php脚本,尽管我只是回显了一些东西!它甚至没有通过任何功能 然后我省略了,class file,用ajax文件检查了php脚本。我只回显了wexckdswendxw,并将ajax中的数据类型更改为“text”…但它仍然没有得到任何值 总之,页面之间的数据根本不会传递!因此,我怀疑这与此处提到的跨域问题有关: 但我不确定这是如何工作的,我应该如何修改我的代码 我的参考代码: login-user.jsJavascript 未在live server中的页面之间传递数据,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我只是在把我的网站上传到实时服务器后才遇到了这个奇怪的问题。在localhost中,我对这些没有问题 问题在于登录和注册功能。让我先谈谈登录 我键入了凭据,发现该页面在f12网络选项卡中被调用。但是该页面没有检索到任何数据!因此,我暂时搁置jquery/ajax,手动检查php页面是否返回任何数据,但仍然没有 现在,流程如下所示: 用户填写的登录表单->来自php脚本的ajax请求->来自类文件的php请求,并返回到ajax->ajax以访问管理仪表板 现在,正如我告诉您的,我排除了ajax请求
/*login user*/
<!--login form submission starts-->
$("document").ready(function(){
$("#login-user").submit(function(){
var data = {
"action": "test"
};
data = $(this).serialize() + "&" + $.param(data);
$.ajax({
type: "POST",
dataType: "json",
url: "login-this-user.php",
data: data,
success: function(data) {
alert(data);
console.log(data);
var i;
for (i = 0; i < data.length; i++)
{
console.log(data[i].email);
console.log(data[i].activate);
console.log(data[i].status);
if($.trim(data[i].status)=='0')
{
//alert("not verified");
$('.invalid-popup-link').trigger('click');
}else
{
//alert("verified");
location.replace("admin/dashboard.php");
}
}//end for
},
error: function( jqXhr, textStatus, errorThrown ){
console.log( errorThrown );
}
});
return false;
});
});
<!--login form submission ends-->
login-this-user.php
<?php
session_start();
include('config.php');
include('class.login.php');
$return = $_POST;
//$return ='{"email":"admin@gmail.com","pass":"admin","action":"test"}';
//$return['json']= json_encode($return);
//
//below code to store in database
$data = json_decode($return, true);
$login = new checkLogin();
$status = $login->checkLogin2($data["email"],$data["pass"]);
$_SESSION['user_id']=$status;
$login = new checkLogin();
$profile = $login->check_profile($data["email"]);
$activated_id=array();
foreach($profile as $k=>$v){
array_push($activated_id,array("email"=>$v['email'],"activate"=>$v['activate'],"status"=>'0'));
$_SESSION['email'] = $v['email'];
$_SESSION['activated_id'] = $v['activate'];
}
//header('Content-Type: application/json');
echo json_encode($activated_id);
?>
阶级
这应该让您知道如何处理同源策略:@Sebastian,谢谢你,但是我如何在我的ajax中使用它呢?
<?php
session_start();
?>
<?php
class checkLogin
{
public $email;
public $password;
public $userId;
public $salt;
public $hpass;
public function __construct()
{
}
public function checkLogin2($param1, $param2)
{
$this->email=$param1;
$this->password=$param2;
$sql = "SELECT * FROM authsessions WHERE email='{$this->email}'";
$statement = connection::$pdo->prepare($sql);
$statement->execute();
while( $row = $statement->fetch()) {
$salt=$row['salt'];
$hashAndSalt=$row['hashpword'];
$user_id=$row['UUID'];
}
if (password_verify($this->password, $hashAndSalt)==true) {
$status = "verified";
$_SESSION['user_id'] =$user_id;
$_SESSION['logged_in']=1;
}else
{
$status = "not verified";
$_SESSION['user_id'] =0;
$_SESSION['logged_in']=0;
}
return $_SESSION['user_id'] = 1;
}
public function check_profile($param)
{
$this->email = $param;
$sql="SELECT * FROM authsessions WHERE email = '{$this->email}'";
$stmt =connection::$pdo->prepare($sql);
$stmt->execute();
$profile=array();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$profile[] = $row;
}
return $profile;
}
}
?>