我有一个搜索表单,如
<form class="navbar-form header_search_form" role="search" name="header_search_form" id="header_job_search_form" method="post">
<div class="input-group">
<input type="text" name="search" id="search" value="" class="header_search_field" placeholder="Search">
<img src="images/search.png">
</div>
</form>
和.htaccess文件如下
#Options -Indexes -MultiViews +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^(.*)/job/search/([a-zA-Z0-9_-]+)?$ $1/job_search.php?query=$2 [NC,L]
Jquery:
$(function() {
$('#header_job_search_form').validate({
rules: {
search: {
required: true
}
},
messages: {
search: {
required: "Please enter keyword."
}
},
submitHandler: function(form) {
var query = $.trim($("#search").val());
query = query.replace(/ /g, "+");
window.location.href = job_seeker_url+'job/search/'+query;
}
});
});
我的项目路径是 www / html / job 。 搜索表单位于 www / html / job / job-seeker 文件夹中。
当我搜索像 php开发者这样的关键字然后工作正常但我什么时候尝试像 php&amp; wordpress开发者所以只有 php 关键字搜索。
答案 0 :(得分:0)
特殊字符需要转义(使用encodeURIComponent
方法)才能形成有效的URI。
window.location.href = job_seeker_url+'job/search/'+ encodeURIComponent(query);