NetworkError:500内部服务器错误 - Laravel Ajax

时间:2017-01-09 08:52:54

标签: php jquery ajax laravel laravel-5.2

当用户选择客户名称(Laravel应用程序)时,我需要显示客户地址。以下是我的jQuery代码:

<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内部服务器错误 - http://localhost/invoice/home/getcustomernameaddress

3 个答案:

答案 0 :(得分:1)

将Json编码更改为以下

json_encode(array('address123'=>$getcustomerdatas->address1,'address456'=>$getcustomerdatas->address2));

答案 1 :(得分:0)

替换下面的代码:

<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',
            dataType:'json',
            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);
            }
        });
    });
})

答案 2 :(得分:-1)

尝试添加斜杠var mainProfile: mainProfile? override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let user1 = self.users[indexPath.row] let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle:nil) let vc: UIViewController = storyboard.instantiateViewController(withIdentifier: "mainProfile") //self.mainProfile?.user2 = user1 // Instead of this line vc.user2 = user1 // use this line self.present(vc, animated: true, completion: nil) }

/