我正在使用Laravel 5.4。
我在index.php中有这段代码:
<span class="input-group-btn">
<button class="btn btn-default ripple" type="button" data-color="#39F2F9" onclick="goto_detail_page();">
<img src="assets/images/search-icon.png" />
</button>
</span>
脚注标注后,脚本会添加到页面底部。 该脚本包括其他无法正常工作的模块,即登录模块:
<script type="text/javascript">
$(document).ready(function () {
var msg = $('#msg').val();
if (msg == "success") {
$('#res-title').css('color','green');
$('#res-title').html('Success');
$('#res-content').html('Your account is activated successfully. You can login now.');
$('#resultModal').modal({
});
}else if(msg == "failed"){
$('#res-title').css('color','red');
$('#res-title').html('Failed');
$('#res-content').html('Something went wroing. Please try again later.');
$('#resultModal').modal({
});
}
});
var current_item_code="";
$(".search_medicine").autocomplete({
search: function(event, ui) {
$('.med_search_loader').css('display','block' );
},
open: function(event, ui) {
$('.med_search_loader').css('display','none' );
},
source: '{{ URL::to('medicine/load-medicine-web/1' )}}',
minLength: 0,
delay: 0 ,
select: function (event, ui) {
item_code = ui.item.item_code;
current_item_code=item_code;
},
response: function( event, ui ) {
$('.med_search_loader').css('display','none' );
}
})
function goto_detail_page()
{
var name=$(".search_medicine").val();
if(current_item_code=="")
{
$.ajax({
url: 'medicine/add-new-medicine',
data: 'name='+name,
type: 'POST',
datatype: 'JSON',
success: function (data) {
if(data.status)
{
$('#new_med_status').show();
$('#new_med_status').addClass('alert-success');
$('#new_med_status').html('This medicine is not available for now. Please check availability later.');
$("#new_med_status").delay(5000).fadeOut("slow");
}else
{
$('#new_med_status').show();
$('#new_med_status').addClass('alert-danger');
$('#new_med_status').html('Something went wrong. Please try again later.');
$("#new_med_status").delay(5000).fadeOut("slow");
}
}
});
}
else{
window.location="medicine-detail/"+current_item_code;
}
}
$("#input-20").change(function() {
if($('#input-20').val().length!=0)
{
$.ajax({
url: 'user/check-session',
type: 'GET',
datatype: 'JSON',
success: function (data) {
if(data==1)
{
$('#upload').click();
}else{
$('#loginModal').click();
}
}
});
}
});
</script>
&#13;
我已经在堆栈溢出模拟器上面运行了上面的代码,但它出现了错误。我不知道我在代码中做错了什么。
在我的网站中,在此代码之前加载了jquery.min.js文件。
请帮助使用javascript代码。这是一个较旧的代码,我正在努力适应更新版本的Laravel 5.4。该代码与laravel 4.2完美配合。