[英]Get parameter in ajax function
可能是一個簡單的問題,但我已經搜索了很長時間,找不到答案。
如果我有這條路線(Laravel):
Route::post('clients/{id}/episode/{episodeid}/plans/{planid}/responsibilities',
array('as' =>'postajax', 'uses' => 'PlanController@postajax'))
問題是:如何從查詢ajax函數的url(id,ep集中,planid)中檢索參數?
$(document).ready(function() {
$('form').on('submit', function(e){
e.preventDefault();
I want to retrieve the parameters here, but how?
Do I actually need to send them as hidden input?
}
});
});
我知道幾個月過去了
$.urlParam = function(name){
var results = new RegExp('[/]' + name + '/([a-z0-9]+)').exec(window.location.href);
if (results===null){
return null;
}
else{
return results[1] || 0;
}
};
並調用:
$.urlParam('param')
例:
客戶端/ 1 /插曲/ 34 /計划/ 67
$.urlParam('clients') // echoes 1
$.urlParam('episodes') // echoes 34
$.urlParam('plans') // echoes 67
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.