Laravel不返回json响应,但返回html响应

时间:2017-01-28 08:58:51

标签: laravel

我有一个ajax函数,它将文件发送到控制器并读取文件,处理并存储它。以上所有功能都完美无缺。但是当我返回json响应ajax调用时。我总是在客户端获得未定义的数据。我不知道这里有什么问题。过去3个小时我一直在敲头。我在其他页面中实现了相同的功能,并且工作正常。当我使用return response()->json(['msg'=>'hello']);回复时,我收到的回复$.ajax({ url: '/resume_upload', type: 'POST', headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }, mimeType: "multipart/form-data", data: form_data, success: function(data) { console.log(data.msg); }, processData: false, contentType: false, error: function(xhr, status, error) { console.log(xhr); alert(xhr); } }); 未发送回复

if($candidate->save()){
  return response()->json(['msg'=>'hello']);// doesn't work                            
  //echo "hello"; //works
}
else{
  return  response()->json(['msg'=>'No hello']); //doesn't work
}

这是我发送响应的控制器代码

SELECT DISTINCT f1.ID_Num
FROM yourtable f1
LEFT OUTER JOIN LATERAL 
(
    SELECT f2.ID_Num FROM yourtable f2
    WHERE f2.code in ('C', 'D') AND f2.ID_Num=f1.ID_Num
    FETCH FIRST ROWS ONLY
) f3 on 1=1
WHERE f3.ID_Num is null

0 个答案:

没有答案