Laravel在实际负载响应中回显HTTP头文本



在前端,我使用ReactjQuery,如下所示:

$.ajax({
url: ...
method: 'POST',
contentType: 'application/json',
dataType: 'json',
success: (response) => { ... },
error: (err) => { ... },
});

我在后端使用Laravel 8.0,在:app/Http/Controllers/Ajax.php上我有:

public function sayHello(Request $request): string
return response()->json([
'status' => true,
])->setStatusCode(200);
}

我的问题是:后端正在回显:

HTTP/1.0 200 OK
Cache-Control: no-cache, private
Content-Type: application/json
Date: Tue, 30 Aug 2022 22:03:48 GMT
{"status":true}

你可以看到它的标题文本与我期望的实际数据相混淆。

你知道如何去掉标题文本吗?

问题在于后端函数的响应类型。

只是删除:: string做到了。

最新更新