最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Laravel send Json to Controller - Stack Overflow

programmeradmin7浏览0评论

I just start using Laravel 5 and i'm facing a problem to send Ajax json data from the view to controller ..

This is my routes.php :

Route::post('ticket','TicketController@store');

 Route::get('ticket', 'TicketController@index');

and this is the controller :

public function store()
{

  return Response::json(Input::get('ticketname'));

}

and Finally for the View i have this simple example to pass just one input :

<script>

$(document).ready(function() {

    $('#go').on("click",function(){


        var ticketname=  ($('.tick_name').val());

                $.ajax({
                    url: 'ticket',
                    type: 'POST',
                    data: {ticketname:$('.tick_name').val()},
                    dataType: 'json',
                    success: function(info){
                        console.log(info);
                    }

                });


    });

});

**IM ALWAYS GETTING THIS ERROR : localhost:8000/ticket

500 Internal Server Error on jquery.js line 4 ..**

CAN anyone help please !

I just start using Laravel 5 and i'm facing a problem to send Ajax json data from the view to controller ..

This is my routes.php :

Route::post('ticket','TicketController@store');

 Route::get('ticket', 'TicketController@index');

and this is the controller :

public function store()
{

  return Response::json(Input::get('ticketname'));

}

and Finally for the View i have this simple example to pass just one input :

<script>

$(document).ready(function() {

    $('#go').on("click",function(){


        var ticketname=  ($('.tick_name').val());

                $.ajax({
                    url: 'ticket',
                    type: 'POST',
                    data: {ticketname:$('.tick_name').val()},
                    dataType: 'json',
                    success: function(info){
                        console.log(info);
                    }

                });


    });

});

**IM ALWAYS GETTING THIS ERROR : localhost:8000/ticket

500 Internal Server Error on jquery.js line 4 ..**

CAN anyone help please !

Share Improve this question asked Apr 18, 2015 at 9:41 Seif waresSeif wares 431 silver badge6 bronze badges 2
  • Take a look at the error log in storage/logs – lukasgeiter Commented Apr 18, 2015 at 9:44
  • ok it says : "exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Class 'App\Http\Controllers\Response' not found' in C:/..... – Seif wares Commented Apr 18, 2015 at 10:07
Add a ment  | 

1 Answer 1

Reset to default 5

Response is an alias in the global namespace. Since you're current namespace is App\Http\Controllers you have to import the class:

use Response;

Or prepend a backslash:

return \Response::json(Input::get('ticketname'));
发布评论

评论列表(0)

  1. 暂无评论