我尝试从一个jQuery插件,它使用了Ajax和JSON在Laravel 4
I'm trying to retrieve data from an Jquery Plugin which uses Ajax and Json in Laravel 4
该插件的部分是在视图中customer.blade.php:
The Plugin part is in the view customer.blade.php:
<script>
var $container = $("#dataTable");
var $console = $("#example1console");
var data = {{ $content }};
$("#dataTable").handsontable({
data: data,
startRows: 6,
startCols: 8,
rowHeaders: true,
colHeaders: [{{ $title }}]
});
var handsontable = $container.data('handsontable');
$container.parent().find('button[name=save]').click(function () {
//alert('we are trying to save');
$.ajax({
url: "/",
data: {"data": 'demo 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.');
}*/
});
});
</script>
在routes.php文件我有:
in Routes.php i have:
// here i wanna send json data to plugin and render the view
Route::get('/', 'CustomerController@getIndex');
// here i wanna retrieve the json-data from the plugin and save it later in db
Route::post('/', 'CustomerController@postSave');
在控制器我有:
public function getIndex() {
//$cust = Customer::get()->toJson();
//$cust = InformationDB::select('Column_Name')->where('table_name', '7_0 - CRONUS (ai-Patches) AG$Customer')->get()->toJson();
// Get Columns
$cust = Customer::select('Name', 'City')->get()->toJson();
// Get Columns Title
$getTitle = Customer::select('Name', 'City')->first()->toJson();
$title = implode(', ',array_keys(json_decode($getTitle, true)));
$title4js = "'" . str_replace(",", "','", $title) . "'";
// Render View
return View::make('customer/customer', array('content' => $cust, 'title' => $title4js));
}
public function postSave() {
$t = Input::all();
return $t;
}
也许有人知道我在做什么错了?
Maybe someone knows what i'm doing wrong?
而不是在你的阿贾克斯后
要求
url: "/",
您必须使用,
url: "/laranav/public/",
在 laranav
将是您的项目目录。
The laranav
will be your project directory.
上一篇:PHP的:$ _SESSION似乎并没有被置1。任何想法?并没有、想法、PHP、_SESSION
下一篇:如何使JQuery的蒙面输入插件在asp.net阿贾克斯更新潘内尔AsyncPostback后工作?插件、内尔、工作、asp