无法将数据从 javascript 传递到 json
Unable to pass data from javascript to json
我想将手头的数据 table 传递给 servlet。我尝试了一种方法,当我尝试传递给 servlet 时我能够获取数据,但我无法从 request.getParameter("forecastdata");
获取数据,该数据为空。请告诉我代码中的错误是什么
ArrayToJson
@WebServlet("/arrayToJson/*")
public class ArrayToJson extends HttpServlet {
@Override
protected void doPost(final HttpServletRequest request,
final HttpServletResponse response) throws ServletException,
IOException {
StringBuffer jb = new StringBuffer();
String line = null;
request.getParameter("forecastdata");
;
}
}
JavaScript
$("#divButtons").find(".btnSubmit").click(function () {
console.log($container.data('handsontable').getData());
var forecast=$container.data('handsontable').getData()
$.ajax({
url: "/Pj_IFRS_P5/arrayToJson",
data: {
forecastdata: forecast
}, //returns all cells' data
dataType: 'json',
type: 'POST',
success: function (data) {
if (data.result === 'ok') {
console.log('Data saved');
} else {
console.log('Save error');
}
},
error: function () {
console.log('Save error. POST method is not allowed on GitHub Pages. Run this example on your own server to see the success message.');
}
});
});
$("#handsontable").handsontable(config);
});
因为您使用的是 jquery,您可以检查您的情况并使用过滤器完全禁用该行。那里有很多例子,甚至在 Whosebug 中也是如此。
一个例子 fiddle 是 HERE
如果你现在是这种情况,这可能会解决问题![=11=]
我想将手头的数据 table 传递给 servlet。我尝试了一种方法,当我尝试传递给 servlet 时我能够获取数据,但我无法从 request.getParameter("forecastdata");
获取数据,该数据为空。请告诉我代码中的错误是什么
ArrayToJson
@WebServlet("/arrayToJson/*")
public class ArrayToJson extends HttpServlet {
@Override
protected void doPost(final HttpServletRequest request,
final HttpServletResponse response) throws ServletException,
IOException {
StringBuffer jb = new StringBuffer();
String line = null;
request.getParameter("forecastdata");
;
}
}
JavaScript
$("#divButtons").find(".btnSubmit").click(function () {
console.log($container.data('handsontable').getData());
var forecast=$container.data('handsontable').getData()
$.ajax({
url: "/Pj_IFRS_P5/arrayToJson",
data: {
forecastdata: forecast
}, //returns all cells' data
dataType: 'json',
type: 'POST',
success: function (data) {
if (data.result === 'ok') {
console.log('Data saved');
} else {
console.log('Save error');
}
},
error: function () {
console.log('Save error. POST method is not allowed on GitHub Pages. Run this example on your own server to see the success message.');
}
});
});
$("#handsontable").handsontable(config);
});
因为您使用的是 jquery,您可以检查您的情况并使用过滤器完全禁用该行。那里有很多例子,甚至在 Whosebug 中也是如此。
一个例子 fiddle 是 HERE
如果你现在是这种情况,这可能会解决问题![=11=]