Reputation: 3647
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.
Upvotes: 0
Views: 724
Reputation: 76880
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
}
});
}
Upvotes: 2
Reputation: 10239
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
}
});
Upvotes: 1