【发布时间】:2012-10-25 23:57:15
【问题描述】:
我有一个使用 CI 会话类的 CI 应用程序。这是我遇到问题的过程:
- 用户加载页面
- Ajax 请求从 DB 获取记录
- 使用该记录的 ID 设置 userdata 变量并执行各种数据库操作
- 用户刷新页面
- Ajax 请求根据上一条记录的会话变量从数据库中获取记录(同一记录不能连续传回两次)
- 将 userdata 变量重新设置为新记录的 ID
等等。等等
这在 chrome 和 FF 中完美运行。但很明显,当我在 IE 中进行测试时 - 不起作用。
ajax 请求被执行,第一条记录被检索。此时会话变量已设置。用户刷新但仍保留相同的记录。
此时,如果我清除会话 cookie 并刷新新记录,则会检索到。
我尝试过改变:
$config['sess_cookie_name'] = 'ci_session';
到
$config['sess_cookie_name'] = 'cisession';
就像我在另一篇文章中看到的那样,但没有运气。还尝试使用数据库进行会话存储,但仍然没有成功。
这里是问题页面:http://givestream.co.uk/stream
在 chrome 或 FF 中加载它,然后刷新或点击“下一步”按钮,您会看到它检索了一个新的慈善机构。在 IE 中试试这个,除非你清除会话 cookie,否则它不起作用。
获取记录的JS函数:
function get_matches(){
var charity;
var user_total;
jQuery.get("/stream/get_charity/", function(data){
charity = data.charity;
user_total = charity.user_totals;
/** CHANGE URL **/
if (history.pushState) {
window.history.pushState("object or string", "Title", "/stream/"+charity.slug);
}
/*****************/
// can user accept?
if(charity.can_donate == 0){
// No
jQuery('.alert-message').show();
} else{
jQuery('.alert-message').hide();
}
// Charity Binding
jQuery('p#char_modal_description').html(charity.description);
jQuery('.char_more_link').attr('id', charity.id);
jQuery('h1#char_name').html(charity.char_name);
jQuery('h2#char_modal_header').html(charity.char_name);
jQuery('p#char_desc').html(charity.description);
jQuery('#website').html('<label>Website</label><a href="'+charity.website+'" style="color:#08C;" target="_blank">'+charity.website+'</a>');
jQuery('#char_total').text('\u00A3'+charity.total);
jQuery('#donors').html(charity.recent_donors);
jQuery('#fans').html(charity.recent_fans);
if (typeof user_total !== 'undefined') {
jQuery('#total_char_month').text('\u00A3'+user_total.total_char_month);
jQuery('#total_char_alltime').text('\u00A3'+user_total.total_char_alltime);
var has_user_seen_stream_notice = user_total.has_user_seen_stream_notice;
if(has_user_seen_stream_notice == false){
jQuery('#stream_help').show();
}
} else{
jQuery('#total_char_month').text('\u00A3'+0);
jQuery('#total_char_alltime').text('\u00A3'+0);
}
/** TWITTER SHARE BUTTON CHANGE URL **/
var twitter = '<a href="https://twitter.com/share" class="twitter-share-button" data-url="http://givestream.co.uk/stream/'+charity.slug+'" data-via="givestreamuk" data-hashtags="socialgiving">Tweet</a>';
jQuery('#twitter_share').html(twitter);
var jstext = '!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");';
var script = document.createElement("script");
script.type = "text/javascript";
script.text = jstext;
jQuery('#twitter_share').append(script);
// *************************************//
/** FACEBOOK SHARE WIDGET **/
var fb = '<iframe src="//www.facebook.com/plugins/like.php?href=http://givestream.co.uk/stream/'+charity.slug+'&send=false&layout=standard&width=280&show_faces=false&action=like&colorscheme=light&font&height=35&appId=119083868224729" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:280px; height:35px;" allowTransparency="true"></iframe>';
jQuery('#fb_share').html(fb);
// ***********************//
jQuery('#char_website').html(charity.website);
jQuery('#sectors').html('<label>Tags</label>'+charity.sectors);
jQuery('#permalink').val('http://givestre.am/stream/'+charity.slug);
jQuery('#refresh').activity(false);
get_charity_gallery();
get_charity_shouts();
}, 'json');
return;
}
【问题讨论】:
-
我相信你知道,CodeIgniter 是一个 PHP 框架。鉴于 PHP 是一种服务器端语言,这本身与 CodeIgniter 无关。相反,这似乎是 JavaScript 或会话问题。向我们展示一些 JavaScript。
-
在 ci 论坛上快速搜索 IE 的 ci 会话问题会显示会话库确实存在一些问题。大多数人似乎通过更改 ci 会话配置来解决它。不过我会放一些js
标签: php internet-explorer codeigniter session