In ASP.NET, how to process data both on the client side (javascript) and on the server side with the presentation of one form?

I have a script in which I use the Google JavaScript JavaScript API to process the address after the form is submitted. However, I want to publish the result that the Google API returns to the server side for further processing within the same form. How can i achieve this? Thanks in advance for your advice.

+3
source share
1 answer

Using jQuery, you can handle it like this:

$(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- .

+3

Source: https://habr.com/ru/post/1717573/


All Articles