So, I create an array with information about the element. I go through all the elements and keep the index. For some reason, I cannot convert this array to a json object!
This is my array loop:
var display = Array(); $('.thread_child').each(function(index, value){ display[index]="none"; if($(this).is(":visible")){ display[index]="block"; } });
I am trying to turn it into a JSON object:
data = JSON.stringify(display);
It does not seem to send the correct JSON format!
If I pass the code like this, it works and sends the information:
data = {"0":"none","1":"block","2":"none","3":"block","4":"block","5":"block","6":"block","7":"block","8":"block","9":"block","10":"block","11":"block","12":"block","13":"block","14":"block","15":"block","16":"block","17":"block","18":"block","19":"block"};
When I make a warning in a JSON.stringify object, it looks the same as a manual encoded one. But that will not work.
I'm going crazy trying to solve this! What am I missing here? What is the best way to send this information to get a manual encoding format?
I use this ajax method to send data:
$.ajax({ dataType: "json", data:data, url: "myfile.php", cache: false, method: 'GET', success: function(rsp) { alert(JSON.stringify(rsp)); var Content = rsp; var Template = render('tsk_lst'); var HTML = Template({ Content : Content }); $( "#task_lists" ).html( HTML ); } });
Using the GET method because I display information (without updating or pasting). Transferring information only to my php file.
END OF DECISION
var display = {}; $('.thread_child').each(function(index, value){ display[index]="none"; if($(this).is(":visible")){ display[index]="block"; } }); $.ajax({ dataType: "json", data: display, url: "myfile.php", cache: false, method: 'GET', success: function(rsp) { alert(JSON.stringify(rsp)); var Content = rsp; var Template = render('tsk_lst'); var HTML = Template({ Content : Content }); $( "#task_lists" ).html( HTML ); } });