我从视图中检索 json:
$container.parent().find('button[name=save]').click(function () {
alert('we are trying to save');
$.ajax({
url: "/laranav/public/",
data: {"data": handsontable.getData()}, //returns all cells' data
dataType: 'json',
type: 'POST',
success: function (res) { console.log(res); alert(res); }
/* error: function () {
$console.text('Save error. POST method is not allowed on GitHub Pages. Run this example on your own server to see the success message.');
}*/
});
然后在Routes.php
// here i make the view
Route::get('/', 'CustomerController@getIndex');
// here i wanna save the retrieved json
Route::post('/', 'CustomerController@postSave');
现在想将检索到的 json 保存在 Controller 中:
public function postSave() {
$t = Input::get('Name');
$c = Customer::find('DKT000142');
$c->Name = $t;
$c->save();
}
检索 json 的东西看起来像:
data[0][Name]:Afrifield Corporation
data[0][City]:Maidstone
data[1][Name]:Amann Informatik AG
data[1][City]:Reinach BL
data[2][Name]:Antarcticopy
data[2][City]:Antwerpen
data[3][Name]:Autohaus Mielberg KG
data[3][City]:Hamburg 36
这给出了一个错误,导致我在 postSave() 函数中做错了
POST http://127.0.0.1/laranav/public/ 500 (Internal Server Error)
send
x.extend.ajax
(anonymous function) 127.0.0.1/laranav/public/:77
x.event.dispatch
v.handle
为了测试,我在这里更改了值,并且它以这种方式工作
public function getOne() {
$c = Customer::find('DKT000142');
$c->Name = 'Amann Informatik AG';
$c->save();
}
我的餐桌课
class Customer extends Eloquent {
//The database table used by the model.
protected $table = '7_0 - CRONUS (ai-Patches) AG$Customer';
public $timestamps = false;
public $primaryKey = 'No_';
//important columns No_ | Name | City and a lot other that i don't wanna touch
}