0

I want to create a list that consists of x number of objects that contains a name and a bool value

I want to create and send the list using ajax when this happens

This is in my Init

$('.si-accordion').click(function () {
            $(this).siblings('.accordion_tab').toggleClass('IsExpanded');
            SendSIInstance();
        });

Here is the method it calls

function SendSIInstance() {
        $('.si-accordion').hasClass('IsExpanded')
        {
            var NameValue = $('.si-accordion').text();

            alert($('.si-accordion').text());
        }
    }

In my example I have 5 tabs (Which has the class si-accordion)

When I click them I toggle the class IsExpanded

I then want to create a list with objects like:

a String: text of si-accordion

A bool: if it has the class IsExpanded (if its there its true, else false)

The list with these 5 objects should then be send using AJAX so I can work with it.

2 Answers 2

2

You could do:

function SendSIInstance() {
    var arrayToSend = [];
    $('.si-accordion').each(function() {

        var expanded = $(this).hasClass('IsExpanded');

        var text = $(this).text();
        var obj = {
            expanded: expanded,
            text: text
        };
        arrayToSend.push(obj);
    });

     //Send arrayToSend through ajax

$.ajax({
    url: "yoururls",
    data: arrayToSend,
    success: function() {
        // code to invoke after ajax call returns
    }
});

}
Sign up to request clarification or add additional context in comments.

Comments

1

Not sure if I understand your question, but try this...

var list = [$('.si-accordion').text(), $('.si-accordion').hasClass('IsExpanded') ...];    
var xmlRequest = $.ajax({
    url: "target.php",
    data: list,
    success: function() {
        // code to invoke after ajax call returns
    }
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.