开发者

.load() with data

开发者 https://www.devze.com 2023-03-05 12:05 出处:网络
I want to load data into a checkout page using .load() to load the pages in a modal window. The data that needs to be loaded is a shipping price value, that needs to be usable on the loaded page.

I want to load data into a checkout page using .load() to load the pages in a modal window. The data that needs to be loaded is a shipping price value, that needs to be usable on the loaded page.

JS

function totalCalc() {
var shipping = ($('#shippingform input[name="shipping"]').val());
$('#cartdialog'开发者_Go百科).load("/ash/shop/checkout.php",[$('#shippingform input[name="shipping"]')]);
alert(shipping);
}

CHECKOUT.PHP

$myTotal = ($subtotal + $_POST['shipping']);

I need the value which is shown through the "alert(shipping);" to be a usable value on checkout.php. You'll see I try to $_POST[] it in a php variable, but it wont work. I must be sending the data wrong...


Per the jQuery API, data sent as a query-string format string through .load() is treated as GET. Data sent as a JSON object is treated as POST. Basically, send it like this:

.load("/ash/show/checkout.php", {shipping: shipping});


As it seems you're using jQuery: http://api.jquery.com/jQuery.post/ or if you want proper control over it, use the ajax method: http://api.jquery.com/jQuery.ajax/

Alternatively, you could add the shipping cost to the URL and use $_GET

0

精彩评论

暂无评论...
验证码 换一张
取 消