Home > Back-end >  Rails 7 Prevent html form from submit to server
Rails 7 Prevent html form from submit to server

Time:12-14

I have an HTML form in erb view template

<form id="megapayForm" name="megapayForm" method="POST">
      <label for="merId" >MerchantId:</label>
      <input type="text" id="merId" name="merId" ><br><br>
      <label for="currency">Currency:</label>
      <input type="text" id="currency" name="currency" ><br><br>
      <input type="submit" id="submit" value="Submit">
</form>

submit.js

$.ajax({
   url: 'https://www.cloudflare.com/cdn-cgi/trace', 
   success: function(data){
            

            
        },
   complete: function(){
      $("#"   formId).attr("action", domain   "acb.do");
      setTimeout(function(){ paymentForm.submit(); }, 100);
   }
});

and rails controller

class transaction
   def index
   end
end

Every time i press submit, instead of redirect to domain "acb.do" , it being redirect to rails server transaction#create How can i make the form being submit and redirect to domain "acb.do"

CodePudding user response:

I fixed this by changing <input type="submit" id="submit" value="Submit">

to <button id="submit">Submit</button>. So when I press the button it does not call to server but only the javascript function

  • Related