所以我有搜索表单(我写在laravel像HTML,但代码是自我解释;纯HTML的答案也欢迎):
{!! Form::model($search, ['url' => 'projects/', 'method' => 'get']) !!}
//Select option I want to include into GET url
{!! Form::select('sort', array(0 => 'Sort: Update Date', 1 => 'Create Date', 2 => 'Follows'), null, ['id' => 'sort', 'class' => 'form-control']) !!}
//A has ajax post request to get B options. A and B shouldn't appear in GET url (exclude A and B alone - they are used to create mixed AB combinations).
{!! Form::select('A', array(...), null, ['id' => 'A', 'class' => 'form-control']) !!}
{!! Form::select('B', array(...), null, ['id' => 'B', 'class' => 'form-control']) !!}
{!! Form::button('Add A B combination', ['class' => 'form-control']) !!}
//Include A and B combination into GET url
{!! Form::select('A_B_combinations[]', array('' => ''), null, ['id' => 'expected', 'class' => 'form-control', 'multiple', 'style' => 'display: none;']) !!}
{!! Form::submit('Search', ['class' => 'form-control']) !!}
{!! Form::close() !!}
我想在get url中只显示排序选项和混合A/B组合变量。
我的示例ajax代码:
$( "#A" ).change(function() {
$.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('input[name="_token"]').attr('value') } });
$.ajax({
type: "POST", /* 'POST' works in post form, 'GET' doesn't work in get form.*/
url: '/ajax/B',
data: {a: a_id},
//success: onSuccess,
dataType: 'json',
success: function( json ) {
$.each(json, function(i, value) {
$("#B").append(
$("<option></option>")
.text(value.display_name)
.val(value.id)
);
});
}
});
});
也许我做错了一切,但我不知道如何做这个?如果我使用post方法,一切都可以正常工作,问题是我希望搜索数据出现在url.
我唯一想到的是:
- 创建包含所有必需输入的get表单,这些输入应该出现在url中条+隐藏输入组合值。
- 第二个post表单在同一页面添加按钮和ajax选项。
- 按下'添加' ->添加组合与jquery隐藏字段在得到形式。