0

I'm stucked here for an hour now, I've searched in some topics on stackoverflow but nothing.

I have this script

<script type="text/javascript">
$('.qty').keyup(function () {
    var $me = $(this),
        $parent = $me.parent('div'),
        total = parseInt($me.attr("data-price"));

    if (isNumber($me.val()) && $me.val() > 0) {
        total = total * $me.val();
    }
    $parent.find('.price').html(total);

    updateTotal();
});

function isNumber (n) {
    return !isNaN(parseFloat(n)) && isFinite(n);
}

function updateTotal () {
    var total = 0;

    $('.qty').each(function () {
        var $me = $(this);

        if (isNumber($me.val()) && $me.val() > 0) {
            total += $me.val() * parseInt($me.attr("data-price"));
        }        
    });

    $('#total').text(total);
    $.ajax({
    type:'POST',
    url:'./s.php',
    data:'price='+total,
    success: function(data){
        alert(data);
    }
    });
}

updateTotal();
    </script>

I want to send the price to the s.php page from the same folder but when I type echo $_POST['price']; I get the undefined index error. var_dump($_POST['price']) returns null. The result from the pop-up page is good, but is not passed to that page.

marius
  • 21
  • 8

1 Answers1

0

I recommend you when you use POST to the server send a JSON object. what you did works for GET method, URL will look like "s.php?total=1000".

try this:

var toSend= {
    total: total
};
$.ajax({
    type:'POST',
    url:'./s.php',
    data: toSend,
    success: function(data){
        alert(data);
    }
});
Noampz
  • 1,185
  • 3
  • 11
  • 19