所以我有搜索表单(我像 HTML 一样用 Laravel 编写,但代码是 self 解释的;纯 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 中。
最佳答案
我想到的唯一想法是:
- 使用应出现在网址中的所有必需输入创建获取表单 条+组合值的隐藏输入。
- 同一页面上的第二个帖子表单,带有添加按钮和 ajax 选项。
- 按“添加”-> 将与 jquery 的组合添加到隐藏字段 获取表格。
关于php - 如何将 ajax post 包含到 get 表单中并在 get url 中排除 ajax 使用的输入?拉维尔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31599262/