1

On my homepage I'm using the maximage fullscreen image plugin. When someone clicks on a specific link (product page), I must find out what the current image in the slideshow is and set it as the background-image in the product index page.

I'm making an ajax call the moment someone clicks the '/producten' link on the homepage and store it as a session variable.

The problem is, it's not making an ajax call, I can't see the POST request in my apache logfile, only the GET request for the '/producten' page. Is it going to fast? Can't I do a POST request just before I make the GET request? I can't pinpoint it. Here's my code:

homepage index:

jQuery(document).ready(function($)
{
    $("a[href='/producten']").click(function() {
        var best;
        var maxz;
        $('.mc-image').each(function() {
            var z = parseInt($(this).css('z-index'), 10);
            if (!best || maxz<z) {
                best = this;        
                maxz = z;
            }
        });
        var bg_image = $(best).css('background-image');
        bg_image     = bg_image.replace('url(','').replace(')','');

        $.post('/producten', {bg_image:bg_image});
    });
});

bg_image is set correctly, I tested it with a console.log(), and I get output.

/producten index:

<?php
    session_start();

    $_SESSION['bg_image'] = $_POST['bg_image'];
?>
4

1 回答 1

0

在 JavaScript 中:

/* $.post('/producten', {bg_image:bg_image}); */
this.href = this.href + '?bg_image=' + escape(bg_image)

在 php 中:

if(isset($_GET['bg_image'])) {
  $_SESSION['bg_image'] = $_GET['bg_image'];
  header('Location: /producten');
  exit;
}
于 2013-10-17T12:41:55.900 回答