且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

JQuery $ .ajax()post - java servlet中的数据

更新时间:2023-12-04 14:33:19

你不想要一个字符串,你真的想要一个JS地图的关键值对。例如,更改:

You don't want a string, you really want a JS map of key value pairs. E.g., change:

 data: myDataVar.toString(),

与:

with:

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.

更新:修正了代码。