下面是我的代码:
请注意,storeSettings 是从 localStorage 中检索的。
var storeSettings = [];
obj.find(o_widgetClass).each(function(){
var storeSettingsStr = {};
storeSettingsStr['id'] = $(this).attr('id');
storeSettingsStr['style'] = $(this).attr('data-widget-attstyle');
storeSettingsStr['title'] = $(this).children('header').children('h2').text();
storeSettingsStr['hidden'] = ($(this).is(':hidden') ? 1 : 0);
storeSettingsStr['collapsed'] = ($(this).hasClass('powerwidget-collapsed') ? 1 : 0);
storeSettings.push(storeSettingsStr);
});
var memberfilter = new Array();
memberfilter[0] = "id";
memberfilter[1] = "style";
var jsonText = JSON.stringify(storeSettings, memberfilter);
//when i alert data, this is the output string i get if before sending it :
/*
[{"id":"widget1"},{"id":"widget2"},{"id":"widget3","style":"black"},{"id":"widget4","style":"purple"},{"id":"widget5"},{"id":"widget6"},{"id":"widget7","style":"black"},{"id":"widget9"},{"id":"widget8","style":"black"},{"id":"widget10"},{"id":"widget11"},{"id":"widget12"},{"id":"widget13"},{"id":"widget14"}]
*/
alert(jsonText);
$.ajax({
type: 'POST',
url: 'get_query.php',
//dataType: 'json',
//contentType: 'json',
data: jsonText,
success: function(data) {
alert(data);
}
});
在 get_query.php 上,我刚刚打印了它:
但它什么也没显示,只是给了我一个空数组。
Array()