Php 在用xdk编写的应用程序发出ajax请求后保留会话
我正在英特尔xdk平台和laravel 5.2.*作为服务器端编写一个混合应用程序。 问题是,当我使用Auth::login()登录时,我会将响应json返回给外部客户端应用程序,然后继续发送ajax请求,但登录后的ajax请求会生成不同的会话,因此我的Auth::user()会丢失。澄清在这种情况下运行在移动设备上的客户端应用程序(混合应用程序)和运行在我公司服务器上的服务器应用程序是非常重要的。我们将非常感激地接受有用的建议,因为我在过去的两天里一直在努力解决这个问题。 这是进行登录的AuthController:Php 在用xdk编写的应用程序发出ajax请求后保留会话,php,jquery,ajax,Php,Jquery,Ajax,我正在英特尔xdk平台和laravel 5.2.*作为服务器端编写一个混合应用程序。 问题是,当我使用Auth::login()登录时,我会将响应json返回给外部客户端应用程序,然后继续发送ajax请求,但登录后的ajax请求会生成不同的会话,因此我的Auth::user()会丢失。澄清在这种情况下运行在移动设备上的客户端应用程序(混合应用程序)和运行在我公司服务器上的服务器应用程序是非常重要的。我们将非常感激地接受有用的建议,因为我在过去的两天里一直在努力解决这个问题。 这是进行登录的Aut
public function postLogin()
{
try
{
$user = User::whereUsername(Request::input('username'))->first();
if(count($user) <= 0)
throw new Exception("שם משתמש לא קיים");
if(!$this->check_password($user,Request::input('password')))
throw new Exception("הזנת סיסמא שגויה");
Auth::login($user);
return response()->json(['success' => 'OK']);
}
catch(Exception $e)
{
return response()->json(['error' => $e->getMessage()]);
}
}
这是客户端登录的第一个ajax请求:
$.ajax({
url: "http://localhost:86/auth/login",
type: "POST",
data:{username:$('#username').val(),password:$('#password').val()},
success: function(result){
if(result.success)
{
af.ui.loadContent("#client_page",false,false,"fade");
}
}
});
最后,来自typeahead元素u的登录后ajax请求可以在远程字段中看到被调用的url:
$(document).ready(function(){
var name_randomizer = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
// You can also prefetch suggestions
// prefetch: 'data/typeahead-generate.php',
// remote: "http://" + connection.getHost() + ":" + connection.getPort() + "/admin/fetch/%QUERY"
remote: "http://" + connection.getHost() + ":" + connection.getPort() + "/fetch/%QUERY"
});
name_randomizer.initialize();
$('#client_search').typeahead({
hint: true,
highlight: true
}, {
name: 'string-randomizer',
displayKey: 'value',
source: name_randomizer.ttAdapter()
});
})) 你能添加一些代码吗?我已经将我的代码添加到原来的帖子中了。谢谢。
$(document).ready(function(){
var name_randomizer = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
// You can also prefetch suggestions
// prefetch: 'data/typeahead-generate.php',
// remote: "http://" + connection.getHost() + ":" + connection.getPort() + "/admin/fetch/%QUERY"
remote: "http://" + connection.getHost() + ":" + connection.getPort() + "/fetch/%QUERY"
});
name_randomizer.initialize();
$('#client_search').typeahead({
hint: true,
highlight: true
}, {
name: 'string-randomizer',
displayKey: 'value',
source: name_randomizer.ttAdapter()
});