Question

I have some trouble with IE, I hope the last for this website…

So, I'm working with Wordpress and I have a couple of protected posts. The template I have to use (chosen by the agency) loaded all post inthe same page, and with thousands of picture, it was not really a good idea. So I choose to load the page with ajax when the visitor click on its item.

So in the same idea for the password forms, they are submitted with Ajax. Before my request, I set a cookie 'pageloaded' to the id of the page to know which post displayed in the response page (one page with all post, so just want to generate the protected post).

When I go to a page, the Ajax send a post variable, but with the form, I can't because the wp-login.php (action page of the form) redirect to the previous page, so I lose the post variable. Then I had the idea to use a cookie ! Well, it works great on all browsers except IE :/

var pageloaded = form.find( 'input[name="pageloaded"]' ).val();
$.cookie('wp_pageloaded', null);
$.cookie('wp_pageloaded',pageloaded, { path: '/' });
var permalink = form.attr('action');
var newurl = permalink;

$.ajax({
    type: 'post',
    headers: {
        "Cache-Control":"no-cache",
        "Expires": "Mon, 26 Jul 1997 05:00:00 GMT" },
    url:newurl,
    data:{
        post_password: post_password,
        pageloaded: pageloaded
    },
    success:function(data, textStatus, jqXHR){
        var container_loaded = $(data).find('#'+pageloaded+' .the-content');
        $(container).html($(container_loaded).html());
        var formNew = $(container).find('form');
        $(formNew).submit(function(event) {
            checkpassword(event);
        });
    }
});

What is exactly the IE reaction : He store the cookie of the first form, so the first request is fine. For the second request, the cookie is still the first.

I reload the page, this time the cookie is set to the second form variable, and the first is ignore, and so on and so forth… the last form sended set the next variable at the page refresh (manually).

Looks like IE set well the cookie, but read the old one in the ajax request :/

Thanks for your help ;)

EDIT : I've tried to do a request first on a php files which do a setcookie(), and then an ajax request on the final file, but still the same problem :/ I will try with session, but I would like to know what's wrong with IE :/

Was it helpful?

Solution

Ok, so the test with the session was an amazing idea ! :P Guess what ? To activate the cookies in the Ajax request for IE you just have to write <? session_start();?> at the beginning of your request files. I don't know why, but it works :/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top