0

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 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[]. Can anyone help me T-T

This is the json output incase you need to see:

"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": ""
}
cdogol
  • 155
  • 11
  • 1
    As , you already have array `items[]` simply push this new value inside it . – Swati Jun 21 '21 at 06:01
  • Hi, we meet again lol i feel dumb ;_; how can i push the new value? – cdogol Jun 21 '21 at 06:24
  • 1
    Using `.push()` ? Also, if you need that result immediately inside your calling function you can try [this](https://stackoverflow.com/a/12615578/10606400) suggestion . – Swati Jun 21 '21 at 06:42
  • oh yess, already push it into new array, but whenever i click the button, the array will be added instead of displaying new array for new id, how can i fix that? – cdogol Jun 21 '21 at 06:58
  • Please elaborate more . – Swati Jun 21 '21 at 07:35
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/234018/discussion-between-swati-and-cdogol). – Swati Jun 21 '21 at 12:11

1 Answers1

1

1: you can declare a global variable and store success data in that, After that you can get that variable data in currentItem function.

2: another option is that you can save data in localStorage and then get data from localstorage in currentItem function.

Adnan Tariq
  • 167
  • 5