我有一个场景,在用户提交表单后,我使用 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 更改为 Controller 操作并进行相应解析。
关于.net - 在 ASP.NET 中,如何通过一个表单提交在客户端(javascript)和服务器端处理数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1418170/