gpt4 book ai didi

javascript - 如何纠正服务器中的 php 重定向错误

转载 作者:行者123 更新时间:2023-11-29 21:56:53 25 4
gpt4 key购买 nike

我的 php 购物车服务器重定向错误到目前为止我所做的是在 jquery 中我必须将商品 id 和单价发送到 shop-cart.php

我的js代码是

var id = getUrlParameter('id');
var unitprice=$(".couponPrice").text();
window.location = 'shop-cart.php?id=' + id +'&unitprice='+ unitprice;

当我点击“添加到购物车”按钮时,它会重定向到

www.domainname/shop-cart.php?id=sp_gt1&unitprice=1

在商店购物车中,我必须生成一个订单 ID,我的 shop-cart.php 代码是

<?php
ob_start();
session_start();
//error reporting
include "script/db.php";
error_reporting(E_ALL);
ini_set('display_errors','1');
error_reporting(E_ERROR | E_PARSE);
?>


<?php
////////order id generate/////////
date_default_timezone_set('Asia/Kolkata');
$stamp = date("ymdhis");

$orderid = $stamp;


if(isset($_GET['OrderId']))
{
$_SESSION['OrderId']=$_GET['OrderId'];
}


/////////////////////////////////////////////////////////////////////////////
// SECTION-1 (if you want to add items to your shopping cart)
/////////////////////////////////////////////////////////////////////////////
if (isset($_GET['id']))
{

$pid = $_GET['id'];
$quantity=1;
$unitprice=$_GET['unitprice'];

$wasFound = false;
$i = 0;

// If the cart session variable is not set or cart array is empty
if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) {

// RUN IF THE CART IS EMPTY OR NOT SET
$_SESSION["cart_array"] = array(0 => array("item_id" => $pid, "quantity" => $quantity,"unit_price"=>$unitprice));
}
else
{
// RUN IF THE CART HAS AT LEAST ONE ITEM IN IT
foreach ($_SESSION["cart_array"] as $each_item) {
$i++;
while (list($key, $value) = each($each_item)) {
if ($key == "item_id" && $value == $pid) {
// That item is in cart already so let's adjust its quantity using array_splice()
array_splice($_SESSION["cart_array"], $i-1, 1, array(array("item_id" => $pid, "quantity" => $each_item['quantity'] + 1,"unit_price"=>$unitprice)));
$wasFound = true;
} // close if condition
} // close while loop
} // close foreach loop
if ($wasFound == false)
{
array_push($_SESSION["cart_array"], array("item_id" => $pid, "quantity" => $quantity,"unit_price"=>$unitprice));
}

}//else
header("location:shop-cart.php?OrderId=".$orderid);
exit();

}//if
?>

我的问题是当我单击本地主机中的“添加到购物车”按钮时,它会显示

http://localhost/mydomainname/shop-cart.php?OrderId=151011020441

但在在线服务器中它显示

http://domainname/shop-cart.php?id=sp_gt1&unitprice=1 

body 的其余部分显示空白。我希望它重定向到显示 orderId,如本地主机中所示,任何帮助将不胜感激。

最佳答案

        $("#add-to-cart").click(function(e) {
e.preventDefault();
error();

});
function error(){
function getUrlParameter(sParam)
{
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++)
{
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam)
{
return sParameterName[1];

}
}
}
var id = getUrlParameter('id');
var unitprice=$(".couponPrice").text();


window.location = 'shop-cart.php?id=' + id +'&unitprice='+ unitprice;




};//add-to-cart////

@RamRaider

关于javascript - 如何纠正服务器中的 php 重定向错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33063078/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com