onsubmit refresh html form

前端 未结 5 638
春和景丽
春和景丽 2021-01-12 00:54

I\'m trying to use Javascript to submit the form\'s data. Here\'s the html.

//input fields here
5条回答
  •  不知归路
    2021-01-12 01:08

    Since this post is tagged with jQuery, I'll offer the following solution:

    $('form').submit(function(e){
      //prevent the form from actually submitting.
      e.preventDefault();
      //specify the url you want to post to.
      //optionally, you could grab the url using $(this).attr('href');
      var url = "http://mysite.com/sendPostVarsHere";
      //construct an object to send to the server
      //optionally, you could grab the input values of the form using $(this).serializeArray()
      var postvars = {};
      //call jquery post with callback function
      $.post(url, postvars, function(response){
        //do something with the response
        console.log(response);
      }, 'json')
    });
    

提交回复
热议问题