Please help me, in my code, Ajax and SweetAlert worked perfectly, but now I get the error on pressing submit:
The Google chrome console shows below error:
Resource interpreted as Stylesheet but transferred with MIME type application/javascript: " http://localhost:8000/js/jquery-3.3.1.min.js ".
Any help is greatly appreciated.
Code
<link rel="stylesheet" type="text/css" href="{!! asset('js/jquery-3.3.1.min.js') !!}">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js"></script>
<script src="//code.jquery.com/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var id1 ={!! $data !!};
var hasil;
var saldo ={{$results}};
$('#jumlahUang').keyup(function () {
var yeah1 = parseInt($('#jumlahUang').val());
var yeah = parseInt($('#jenisTransaksi').val());
if (yeah == 1) {
hasil = saldo + yeah1;
} else {
hasil = saldo - yeah1;
}
if (hasil < 0) {
swal("Error", "SALDO ANDA KURANG");
} else {
$('#debugg').val(hasil);
}
});
$('#formInput').submit(function (e) {
e.preventDefault();
var id1 ={!! $data !!};
var link = "/nambahTransaksi/" + id1.id;
swal({
title: "Konfirmasi transaksi",
text: "proses transaksi?",
type: "info",
showCancelButton: true,
confirmButtonColor: "#1da1f2",
confirmButtonText: "Yakin, dong!",
closeOnConfirm: false,
showLoaderOnConfirm: true,
}, function () { //apabila sweet alert d confirm maka akan mengirim data ke simpan.php melalui proses ajax
$.ajax({
url: link,// ini salah anjing
type: 'get',
data: $('#formInput').serialize(), //serialize() untuk mengambil semua data di dalam form
dataType: "HTML",
success: function () {
setTimeout(function () {
swal({
title: "transaksi berhasil dilakukan",
text: "Terimakasih",
type: "success"
}, function () {
window.location.href = "/detailTransaksi";
});
}, 2000);
},
error: function (xhr, ajaxOptions, thrownError) {
setTimeout(function () {
swal("Error", "Tolong cek kembali SALDO anda");
}, 2000);
}
});
});
});
})
</script>
you have to use this js files,i hope its work for you.
<script src="{{ asset('assets/global/plugins/jquery.min.js') }}" type="text/javascript"></script>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
example
$("#sub").click(function() {
var startDate = $('#fromDate').val();
var endDate = $('#toDate').val();
if (startDate !='')
{
if(endDate == '')
{
swal("Error!", "Please Select To Date field", "error");
return false;
}
}
else
{
swal("Error!", "Please Select From Date field", "error");
return false;
}
if(startDate > endDate)
{
//alert("Please Select To Date Grater Than"+startDate);
swal("Error!", "Please Select To Date Grater Than "+startDate, "error");
return false;
} });
You have this line set to be a stylesheet but it is actually a .js file.
<link rel="stylesheet" type="text/css" href="{!! asset('js/jquery-3.3.1.min.js') !!}">
Try using:
<script src="{!! asset('js/jquery-3.3.1.min.js') !!}"></script>
Also, why are you including JQuery twice? Just move your second declaration to the top, the line that says:
<script src="//code.jquery.com/jquery-3.3.1.min.js"></script>
It needs to be declared before you add SweetAlert because SweetAlert is dependent on it.
EDIT: This is only a partial answer. OP still has another issue outside of this. Wanted to leave this up however as it was useful in solving part 1 of his problem.
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.