[SalesForce] Preventing a reload/refresh on form submit in Lightning

i have created a form in salesforce lightning using form tag and one button there is inputtype="submit", value="submit", i dont want to reload the page when submit clicked. please help me out.

<aura:component> 
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <form action=" url" method="post" I'd="form"/>
    <Inputtype="submit",value="submit" >
</aura:component>

doInit: function(component, event, helper) 
{
    $( "form" ).submit(function( event ) {
        event.preventDefault();
        return false;
    });
}

it is not working if i used in doInit.

Update:

 submitForm : function () {
            $( "form" ).submit(function( event ) {

       event.preventDefault();
       return false;
    });
        }

this submitFrom() function i have called in onclick method for button.

<input type="submit" name="submit" onsubmit="submitForm()"/>

but it is not working. page is still loading.

Best Answer

I got and answer on that.. i have used

          $("form").submit(function( event ) {
              event.preventDefault();
              url = $form.attr( 'action' );
              var posting = $.post( url, { email: $('#email').val() } );
              posting.done(function( data ) {
               alert("success")
                   });
               alert("submitted")
                 });

this is working and page is not loading againg but i am unable to submit that form and update the form with values.

Related Topic