我是laravel的新手,所以我如何得到 输出然后获取textarea中的输入值,然后使用ajax将其保存到db(如果有) CAR1 car2已经 然后,如果我把车3放在textarea,它应该添加car3
视图
<html>
<head>
<title>
asdf
</title>
</head>
<body>
<input type="text" id="cars"/>
<button class="create-car"> Create </button>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script type="text/javascript">
function get (){
var g = document.getElementbyID("cars").value;
}
$(document).ready(function() {
$.get('/').success(function(data) {
data.forEach(function(car) {
console.log(car);
$('body').append(car.name + "<br/>");
});
});
$('.create-car').click(function() {
var data = {
/*"name": "Honda",
"owner": "Someone"*/
"name": g.getValue(),
"owner": "zxc"
}
$.post('/', data);
});
});
</script>
</body>
路线
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
return App\Car::all();
});
Route::post('/', function () {
return App\Car::create(Request::all());
});
Route::get('/ajax', function () {
return view('index');
});