【发布时间】:2014-01-14 07:29:04
【问题描述】:
我想要做的是将一个变量从我的视图传递给一个控制器函数。问题是我从来没有路由到我的控制器的函数存储区。所以我无法检查我是否也得到了变量。 ajax 功能似乎可以工作(显示警报),但我从来没有从我的控制器收到消息成功..
到目前为止,我的路线文件是:
Route::get('pois', array(
'uses' => 'MapController@create',
'as' => 'pois.create'
));
Route::post('pois', array(
'uses' => 'MapController@store',
'as' => 'pois.get'
));
我的地图控制器是:
public function create()
{
$bar=new Map;
$rest=new Map;
$mag=new Map;
$bar = Map::where('type', '=', 'bar')->take(10)->get();
$rest = Map::where('type', '=', 'restaurant')->take(10)->get();
$mag = Map::where('type', '=', 'magazine')->take(10)->get();
return View::make('pois.markers')->with('bar',$bar)->with('rest',$rest)->with('mag',$mag);
}
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
dd('suceess');
}
我的 javascript-jquery 脚本如下:
function ajaxCall(id) {
$.ajax
({
type: "POST",
url: "pois",
data: {"id" : id},
success: function(response)
{
alert('ok');
}
});
}
function checkBoxes(elem){
if(document.getElementById(elem).checked==true){
ajaxCall(elem);
}
else{
clearMarkers(elem);
}
}
Bellow 也是我的 HTML:
@section('main_contents')
<br/>
<div class="text-center">
<label class="checkbox-inline">
<input type="checkbox" id="bar" name="group" value="option1" onClick="checkBoxes(this.id)"> Καφετέριες
</label>
<label class="checkbox-inline">
<input type="checkbox" id="restaurant" name="group" value="option2" onClick="checkBoxes(this.id)"> Εστιατόρια
</label>
<label class="checkbox-inline">
<input type="checkbox" id="magazine" name="group" value="option3" onClick="checkBoxes(this.id)"> Μαγαζιά
</label>
<br/>
</div>
<div id="map" style="height:500px;"></div>
@stop
【问题讨论】:
标签: javascript php jquery ajax laravel-4