The given code I have written in Php file using codeigniter framework but I want to write below code in external Js file and load in header via script src how to do this in external_script.js I tried this but not getting this way it is refreshing page when I click submit button.
Here this way I am passing base_url to script file external.js
<script type="text/javascript">
base_url: '<?= base_url() ?>',
</script>
<script type="text/javascript" src="<?= base_url();?>files/external.js"></script>
//Below code in external.js
$("body").on("submit","#submit_form",function(event){
event.preventDefault();
$('#sub_btn').prop("disabled", true);
$.ajax({
url: <?=base_url('Controller/method name')?>
type: "POST",
data: new FormData(this),
cache: false,
contentType: false,
processData: false,
success: function (response) {
if (response === 'success') {
$(".show_res").html('information updated successfully');
$('#sub_btn').prop("disabled", false);
document.getElementById('submit_form').reset();
}
}
});
}));