[英]In ASP.NET, how to process data on both client side (javascript) and server side with the one form submission?
我有一个场景,我在用户提交表单后使用Google Map JavaScript API来处理地址。 但是,我想发布结果,即Google API返回到服务器端,以便在同一表单提交中进一步处理。 我怎样才能做到这一点? 提前感谢您的建议。
使用jQuery,您可以像这样处理它:
$(document).ready(function() {
$("form").submit(function(e) {
// blocks form from being submitted, which you'll handle later
e.preventDefault();
// call google apis
// build data to submit
var data = {
formData: $("something").val();
// could use formData: $(this).serialize(); instead,
// more server-side parsing required though
// add additional data from the google service to data object
};
// submit the form with serialized data
$.post("/serverurl", data);
});
});
如果您正在使用Webforms,请将serverurl设置为.ashx处理程序,解析提交的数据(将设置为Request.Form []值)。 如果您正在使用MVC,请将服务器URL更改为控制器操作并进行相应的解析。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.