更新时间:2023-12-04 14:33:37
你不想要一个字符串,你真的想要一个键值对的 JS 映射.例如,改变:
You don't want a string, you really want a JS map of key value pairs. E.g., change:
data: myDataVar.toString(),
与:
var myKeyVals = { A1984 : 1, A9873 : 5, A1674 : 2, A8724 : 1, A3574 : 3, A1165 : 5 }
var saveData = $.ajax({
type: 'POST',
url: "someaction.do?action=saveData",
data: myKeyVals,
dataType: "text",
success: function(resultData) { alert("Save Complete") }
});
saveData.error(function() { alert("Something went wrong"); });
jQuery 理解这样的键值对,它不理解大字符串.它只是将其作为字符串传递.
jQuery understands key value pairs like that, it does NOT understand a big string. It passes it simply as a string.
更新:代码已修复.