douzongluo7542 2016-05-01 11:29
浏览 40

如何获取响应或将数据从控制文件传递到Laravel中的js文件

I want to pass data from control file to js file with laravel and ajax, I have tried but I got error all time, How can I pass just one value or array. In this example I have email, name and country in users table.

Code Here.

Control file:

public function showData(Request $request)
{
    $userid = User::find($request['userId']);
    $user = DB::table('users')->where('id', '=', $userid )->first();
    return response(.....);
}

JS file:

.done(function() {
    // pass data or do something . . . 
});

Should I use .done or success ? which better ?

  • 写回答

1条回答 默认 最新

  • duanjia2772 2016-05-01 12:29
    关注
      return response()->json($user);
    

    i think success is better and check this https://github.com/laracasts/PHP-Vars-To-Js-Transformer

    its easy to use+ with docs and you can find a tutorial about it in the laracasts

    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?