简体   繁体   English

如何通过参数将AJAX成功传递给另一个function?

[英]How to pass AJAX success into another function with parameter?

In my blade, I got this script:-在我的刀片中,我得到了这个脚本:-

function itemDetails(item_id){

    $.ajax({
            type:'GET',
            url: './itemDetails/'+item_id,
            datatype: 'json',
            success: function(response){

                $('#modalTitle').text(response.data.name);
                $('#modalID').text(response.data.id);
                }
            });
    }

I have another function which I call it when user clicks on the button with parameter,我还有另一个 function,当用户单击带有参数的按钮时,我会调用它,

function currentItem(id, itemAvailability, maxItem){}

Now, how do I call the results in AJAX success into my currentItem , because i need to store all the data in a new array called items[] .现在,我如何将 AJAX success 中的结果调用到我的currentItem中,因为我需要将所有数据存储在一个名为items[]的新数组中。 Can anyone help me TT谁能帮我TT

This is the json output incase you need to see:这是 json output,您需要查看:

"data": {
    "name": "Fried Chicken Wings",
    "id": 99,
    "price": "$13.00",
    "options": [
        {
            "id": 1,
            "item_id": 99,
            "name": "Size",
            "options": "small,medium"
        }
    ],
    "has_variants": true,
    "description": "Fried Chicken Wings"
},
"status": true,
"errMsg": ""
}

1: you can declare a global variable and store success data in that, After that you can get that variable data in currentItem function. 1:你可以声明一个全局变量并将成功数据存储在其中,之后你可以在currentItem function中获取该变量数据。

2: another option is that you can save data in localStorage and then get data from localstorage in currentItem function. 2:另一种选择是可以将数据保存在localStorage中,然后在currentItem function中从localstorage中获取数据。

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

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