我已经尝试过让它工作一段时间。
我正在做一个Web应用程序,希望将URL设置为example.net/param/param/param/param等。
我已经在这里完成了我的其中一页:
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*)$ /i/index.php?id=$1 [NC,L]
这需要example.com/i?id=1212112
并将其变成example.com/i/1212112
。
但是,我有另一个目录,结果是从domain.com(索引)获取POST。我在结果内部有一个表单,可通过AJAX调用获取信息并构建表单。该代码如下。
<script>
$(document).on('change', 'select', function() {
var itemSpecifics = document.getElementById('itemSpecifics');
var submitButton = document.getElementById('submitButton');
var narrowHelper = document.getElementById('narrowHelper');
narrowHelper.innerHTML = "select all of the filters you want to search by.";
var loading = document.getElementById('loading');
loading = loading.style.display = "block";
document.getElementById("submitButton").style.display = "none";
//$("#submitButton").empty();
$("#itemSpecifics").empty();
$.ajax({
type : 'GET',
url : 'refine_search.php',
data: {category: $(this).val()},
cache: false,
dataType : 'json',
encode : true,
traditional: true,
success: function (response, status, xhr) {
console.log(response);
for (var i = 0; i < response.length; i++) {
console.log(response[i].name);
itemSpecifics.innerHTML += "<div style=\"color:#ec5b6e\">" + response[i].name + "</div>";
//console.log(response[i].value);
for (var j = 0; j < response[i].value.length; j++) {
console.log("-- " + response[i].value[j].value);
var checkbox = document.createElement('input');
checkbox.type = "checkbox";
checkbox.name = "cb[]";
checkbox.value = response[i].name + "@" + response[i].value[j].value;
checkbox.id = "checkboxid";
var label = document.createElement('label')
label.htmlFor = "id";
label.id = "label";
label.appendChild(document.createTextNode(response[i].value[j].value));
itemSpecifics.appendChild(checkbox);
itemSpecifics.innerHTML += " ";
itemSpecifics.appendChild(label);
itemSpecifics.innerHTML += "<br>";
$("input[type='checkbox']").on('change', function(){
console.log($(this).val());
});
}
}
submitButton.innerHTML = "SUBMIT";
document.getElementById("loading").style.display = "none";
document.getElementById("submitButton").style.display = "block";
},
error: function (xhr, status, error) {
console.log(error);
}
});
// if you want to do stuff based on the OPTION element:
var opt = $(this).find('option:selected')[0];
// use switch or if/else etc.
});
</script>
这会吐出很多复选框和标签。选择它们后,我将获取值并将其保存在cb []数组中作为复选框的名称。对于形式有这个。
<form action="example.net/results" method="GET">
提交此表单后,我得到了...
https://www.example.com/results/?cb%5B%5D=Model%40Xbox+360+Arcade&cb%5B%5D=Model%40Xbox+360+Core&cb%5B%5D=Model%40Xbox+360+E&cb%5B%5D=Model%40Xbox+360+Elite
我希望做的是将上述URL路由到...
https://www.example.com/results/Model%40Xbox+360+Arcade/Model%40Xbox+360+Core/Model%40Xbox+360+E/Model%40Xbox+360+Elite
或者,删除&cb%5B%5D=
有人可以帮我吗?我尝试对表单执行POST方法,但是当我这样做时,代码仅获取最后的cb =,然后仅获取字符串的第一个字符。