取消在ajax中通过post传递的变量的设置

unset a variable passed through post in ajax

本文关键字:变量 设置 post ajax 取消      更新时间:2023-09-26

我有ajax代码在我的javascript文件如下:

// Default settings for Ajax requests
        $.ajaxSetup({
            type: 'POST',   
            url: path + '/relay.php'+ '?curr=' + currency + "&ver=" + Math.random(),
            success: function(response) {
                // Refresh the cart display after a successful Ajax request
                container.html(response);
                $('#jcart-buttons').remove();
            },
               .......

上面的代码将发布为(在firebug中):

POST http://www.myshop.com/cart/relay.php?curr=EUR&ver=0.5750630930208085

我有一个remove函数如下:

function remove(link) {
        // Get the query string of the link that was clicked
        var queryString = link.attr('href');
        queryString = queryString.split('=');
        // The id of the item to remove
        var removeId = queryString[1];
        // Remove the item and refresh cart display
        $.ajax({
            type: 'GET',
            data: {
                "jcartRemove": removeId,
                "jcartIsCheckout": isCheckout
            }
        });
    }

删除将显示如下(firebug)

GET http://www.myshop.com/cart/relay.php?curr=EUR&ver=0.5750630&jcartRemove=5

我也需要删除当前变量…

我怎么能做到它在我的删除链接代码上面??

更改AJAX方法,因为您正在从URL 发送参数(这是get方法发送参数)

$.ajaxSetup({
        type: 'GET',   
        url: path + '/relay.php'+ '?curr=' + currency + "&ver=" + Math.random(),
        success: function(response) {
            // Refresh the cart display after a successful Ajax request
            container.html(response);
            $('#jcart-buttons').remove();
        },

$.ajax({
        type: 'POST',
        data: {
            "jcartRemove": removeId,
            "jcartIsCheckout": isCheckout
        }
    });

链接如下:

AJAX链接


链接文章
链接得到

1。您需要更改$。ajaxSetup方法中使用的urlUrl: path + '/relay.php'+ '?curr=' + currency + ' &ver= ' ' + Math.random()包含curr和ver参数,但是你不需要在Remove Function中添加curr变量,所以你需要从这个url中删除curr变量,只在特定的ajax调用中添加curr变量。

2。默认情况下你的url应该是Url: path + '/relay.php?ver=' + Math.random()

并在随后的ajax调用中使用data参数添加当前变量。

3。现在,当您调用remove函数时,默认查询字符串将不包含当前参数。

function remove(link) {
        // Get the query string of the link that was clicked
        var queryString = link.attr('href');
        queryString = queryString.split('=');
        // The id of the item to remove
        var removeId = queryString[1];
        // Remove the item and refresh cart display
        $.ajax({
            type: 'GET',
            data: {
                "jcartRemove": removeId,
                "jcartIsCheckout": isCheckout
            }
        });
    }

http://www.myshop.com/cart/relay.php?ver=0.5750630& jcartRemove = 5, jcartIsCheckout = true如果isCheckout=true获得http://www.myshop.com/cart/relay.php?ver=0.5750630& jcartRemove = 5, jcartIsCheckout = falsein case isCheckout=false

如果你有任何疑问,请发帖