通过Ajax调用设置laravel VAR会议的JavaScript和另一呼叫相同的VAR值获得 [英] set var session in laravel through ajax call in javascript and get with another call the same var value
问题描述
laravel的缓存为我工作,但在不同的浏览器是相同的值。
The cache of laravel works for me but is the same values in different browsers.
我想设定一个会议laravel,并设置会话变量通过Ajax调用,然后在另一个Ajax调用获取会话变量。
I'm trying to set a session in laravel, and set session variable through ajax call, then in another ajax call get that session variable.
$.ajax({
type: "post",
url: url+'setdata',
data: $('form#data').serialize(),
dataType: "json",
processData: false,
async: false,
success: function (data) {
}
});
$.ajax({
type: "post",
url: url+'getdata,
data: $('form#data').serialize(),
dataType: "json",
processData: false,
async: false,
success: function (data) {
}
});
在第一个ajax请求,我打电话从laravel一个控制器的功能。这个函数执行:
In the first ajax request, I call a function from one controller in laravel. This function performs:
Session::put('examplekey', 800);
在第二个请求,控制器功能检索会话ID:
In the second request, the controller function retrieves the session ID:
$var = Session::get('examplekey');
return array($var);
我的问题是,在第二Ajax调用会话消失。我如何可以在session_start()设置相同的会话同一个用户,在纯PHP;
My problem is, in the second ajax call the session disappears. How can I can set the same session for the same user, in pure php with session_start();
推荐答案
我有同样的问题,只是发现了一个潜在的解决方案:
I had the same problem and just found a potential solution:
我发现与laravel 3.会议坚持叫你需要正确返回响应的AJAX类似的问题。
I found a similar problem relating to laravel 3. For the session to persist in an ajax call you need to return the response correctly.
return json_encode($response);
这是造成问题的原因。这不是它出现在一个有效的响应,使会话持续。将其更改为:
This is causing the problem. It's not it appears a valid response to enable the session to persist. Change it to:
return Response::json($response);
这使会议坚持!
由于某种原因,一个正常的表单提交,或致电该方法允许第一个,但阿贾克斯没有。
For some reason a normal form submit or call to the method allows the first one but ajax does not.
我见过的其他地方引用有关方法影响了会议的回声声明 - 我想退货时,必须表现类似回声
I've seen references elsewhere about echo statements in the method affecting the session - the return I suppose must behaving similar to an echo
这是触发该解决方案后: http://forumsarchive.laravel.io/viewtopic.php?id=1304
This is the post that triggered the solution: http://forumsarchive.laravel.io/viewtopic.php?id=1304
这篇关于通过Ajax调用设置laravel VAR会议的JavaScript和另一呼叫相同的VAR值获得的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!