C# Laravel API向RESTC返回空白/空#
我将Laravel用作与我的C#应用程序通信的web API 我正试图提出一个post请求:C# Laravel API向RESTC返回空白/空#,c#,laravel,C#,Laravel,我将Laravel用作与我的C#应用程序通信的web API 我正试图提出一个post请求: if ($validate){ // Store query results in a variable $user = Login::where([ ['BR_ID', $BR_ID], ['ClientID', $ClientID], ['ClientChkID', $Cl
if ($validate){
// Store query results in a variable
$user = Login::where([
['BR_ID', $BR_ID],
['ClientID', $ClientID],
['ClientChkID', $ClientChkID],
['LastName', $LastName]
])->get();
// Format contact number
$ContactNo = $user[0]->ContactNo;
$otpController = new \App\Http\Controllers\OTPController();
$phone = $otpController->CheckContactValidity($ContactNo);
// Append formatted number to laravel's collection object
$user[0]->ValidContactNo = $phone;
// send back a response
return response()->json($user[0], 200);
} else {
return response()->json(["error"=>"Client does not exist"], 204);
}
if语句中的代码运行良好,返回的一切都很好。但是,else部分根本不返回任何内容
基本上,行
return response()->json([“error”=>“Client not existence”]、204)
总是返回”
而不是{“error”:“客户端不存在”}
这是胡说八道。204状态码是无内容响应,那么为什么要返回某些内容呢
您可以通过以下方式检查响应代码:
$.ajax({
url:“/test”,
键入:“GET”,
contentType:“应用程序/json;字符集=utf-8”,
数据类型:“json”,
成功:功能(res){
}
})
.done(函数(数据、文本状态、jqXHR){
console.log(jqXHR.status);//204
});
现在有道理了。我想204号还是应该寄些东西,因为它在《邮递员》里有。