在前端,您可以尝试使用以下示例代码来处理您的AJAX请求,并等待正确的响应
$.ajax({
url: 'example.com/ajaxRequest',
type: 'GET',
dataType: 'json',
success: function (data) {
console.log(data);
}
});
在我们的后端,在您的控制器中,您需要确保您使用echo语句来输出JSON数据。例如:
public function ajaxRequest()
{
$response = array(
'success' => true,
'message' => 'Hello World!'
);
header('Content-Type: application/json');
echo json_encode($response);
}
请注意,我们必须设置内容类型为JSON,并使用echo语句输出JSON编码的数组。
如果仍然看不到正确的响应,请确保您在浏览器的开发人员工具中查看后端返回的响应。