从Laravel4中的Jquery Ajax Json检索值

从Laravel4中的Jquery Ajax Json检索值,jquery,ajax,json,laravel,laravel-4,Jquery,Ajax,Json,Laravel,Laravel 4,我试图从一个Jquery插件中检索数据,该插件在Laravel4中使用Ajax和Json 插件部分位于customer.blade.php视图中: <script> var $container = $("#dataTable"); var $console = $("#example1console"); var data = {{ $content }}; $("#dataTable").handsontable({ data: data, startR

我试图从一个Jquery插件中检索数据,该插件在Laravel4中使用Ajax和Json

插件部分位于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>
在控制器中,我有:

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;
}

也许有人知道我做错了什么?

在您的
ajax post
请求中,而不是

url: "/",
你必须使用

url: "/laranav/public/",

laranav
将是您的项目目录。

您在控制台中得到的输出是什么?什么都没有,我甚至可以看到chromedevtool->network与本地主机建立了一个新的连接,当我单击save按钮并在标题信息中显示我想要保存的json数据i。。使用此
$.ajax({url:/laranav/public/),数据:{“data”:“demo data”},//返回所有单元格的数据数据类型:'json',类型:'POST',成功:函数(res){console.log(res);警报(res);})现在你得到了什么?任何错误?从控制器使用此
公共函数postSave(){$t=Input::all();return$t;}
遗憾的是,并非一切都像以前一样,只是什么都没有发生,只是每次保存时都会出现连接…@user2834172不客气,如果您有任何其他疑问,您可以问。我应该提出一个新问题吗?从检索到的json中,我想现在将其保存在db
公共函数postSave(){//$t=Input::all();$t=Input::get('Name');$c=Customer::find('dkt00142');$c->Name=$t;$c->save();//return$t;}
给出状态错误500提出新问题,您应该解释在控制台中扩展请求url时得到的错误字符串,并解释表字段名称。
url: "/laranav/public/",