当用户选择客户名称(Laravel应用程序)时,我需要显示客户地址。以下是我的jQuery代码:NetworkError:500内部服务器错误 - Laravel Ajax
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$('#customername').change(function() {
var choice = jQuery(this).val();
$.ajax({
url:'{{URL('home/getcustomernameaddress')}}',
type:'POST',
data : {'id' : choice,'_token': '{{ csrf_token() }}'},
success : function(response) {
alert(response);
var json = $.parseJSON(response);
$('span#message').html(json.address123);
$('span#message1').html(json.address456);
}
});
});
})
</script>
家/ getcustomernameaddress
$data = $_POST;
$getcustomerdatas=DB::table('customers')->where('id', '=', $data["id"])->first();
echo json_encode(array('address123'=>$getcustomerdatas["address1"],'address456'=>$getcustomerdatas["address2"]));
显示以下错误:
"NetworkError: 500 Internal Server Error - http://localhost/invoice/home/getcustomernameaddress "
告诉你laravel错误堆栈,你的route.php –
路线::职位(” getcustomernameaddress', '发票\ InvoiceController @ getcustomernameaddress'); @Kris Roofe – Karthik
尝试通过json响应:return response() - > json($ response); –