I have a CI application that uses the CI session class. Here’s the process I’m having trouble with:
- Users loads page
- Ajax request to get record from DB
- Set userdata variable with that record’s ID & do various DB stuff
- User refreshes the page
- Ajax request to get record from DB based on the session variable of the previous record (same record can not be passed back twice in a row)
- re-set userdata variable to new record’s ID
etc. etc.
This works perfectly in chrome and FF. But obviously when I come to test in IE – doesn’t work.
The ajax request is executed and the first record is retreived. At this point the session variable has been set. User refreshes but the same record remains.
At this point if I clear session cookies and refresh the new record is retrieved.
I’ve tried changing:
$config['sess_cookie_name'] = 'ci_session';
to
$config['sess_cookie_name'] = 'cisession';
Like I saw in another post but no luck. Also tried using DB for session storage but still no luck.
Here is the problem page: http://givestream.co.uk/stream
Load this in chrome or FF and either refresh or hit the ‘Next’ button and you’ll see it retrieves a new charity. Try this in IE and it doesn’t work unless you clear session cookies.
JS function to get record:
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;
}
Fixed!
It wasn’t a ci_session issue it would seem.
I dug a bit deeper and added
Into the controller that does the json response to see if the ajax request was actually reaching the controller and it turned out none of the IE ajax get requests actually made it to the controller.
Turns out that even though the IE network inspector acknowleged the get request it was actually using cached ajax responses.
I added
To the top of the js script and boom. sorted.
Thanks to @Laurencei for the help though!