所以我有搜索表单(我用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() !!}
我想在获取网址时只显示排序选项并混合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中。
答案 0 :(得分:0)
我想出的唯一想法是: