简体   繁体   English

使用ajax代码将php变量从一页传递到另一页

[英]pass a php variable from one page to another page with ajax code

I dunno whether my heading is correct or not ?? 我不知道我的标题是否正确??

While loading the shop.php page i have a variable named $curr set with values from GET like "GBP". 在加载shop.php页面时,我有一个名为$ curr的变量,它带有GET中的值,例如“ GBP”。

$curr = $_GET['cur'];
<script type="text/javascript" src="js/cart.js"></script> 

While loading the page the cart.js code calls another page like as follows: 加载页面时,cart.js代码将调用另一个页面,如下所示:

GET http://myshop.com/cart/config-loader.php?ajax=true

The javascript code which loads the config-loader page is as follows: 加载config-loader页面的javascript代码如下:

var config = (function() {
        var config = null;
        $.ajax({
            url: path + '/config-loader.php',
            data: {
                "ajax": "true"
            },
            dataType: 'json',
            async: false,
            success: function(response) {
                config = response;
            },
            error: function() {
                alert('Ajax error: Edit the path in cart.js to fix.');
            }
        });
        return config;
    }());

I need to get the url passed as: http://myshop.com/cart/config-loader.php?ajax=true&curr=GBP 我需要将网址传递为: http : //myshop.com/cart/config-loader.php?ajax=true&curr=GBP

so that i can get the $_GET['curr'] value in config-loader.php page. 这样我就可以在config-loader.php页面中获得$ _GET ['curr']值。

My aim is to change the value USD to any other value like GBP in config-loader.phpge: 我的目标是将config-loader.phpge中的USD值更改为GBP等其他值:

if (!$config['currencyCode']) $config['currencyCode'] = 'USD';

How can i do this in above code ?? 我如何在上面的代码中做到这一点? Help requested from experts. 专家要求的帮助。

Use: 采用:

        data: {
            "ajax": "true",
            "curr": <?php echo json_encode($curr) ?>
        },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM