简体   繁体   中英

how to avoid default form action on laravel 5.4?

i integrate my html form on laravel. it has html registration form. in that form i didn't put form action . so when i submit the form it post the data to the same page.but i write a javascipt click event to get form data and post data to the destination with ajax. but when i click the submit button i perform these two actions .. 1. posting data to the same page and another my ajax call.. i want only ajax. not that .. how to solve this?

<form class="form-horizontal" role="form" id="addUser">input fields</form>
$('#addUser').on('click',function(){some code})

preventDefault() is what you're looking for. Here is the jQuery documentation

$('#addUser').on('click',function(e){
 e.preventDefault()
 ...rest of the code...
})

Hey you can use submit event of form like this.

$(document).on('submit','form#addUser',function(e){
    e.preventDefault(); //This prevents the default submit action that might refresh the page
    .. code
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM