Han*_*ani 6 javascript .htaccess jquery
我在错误的URL中获取错误但不是在firefox和chrome中.
基本上,我有一个名为文本搜索的文本域.我在htaccess中使用jQuery和rewriterule来内部重定向页面.我在localhost上,所有文件都在一个名为test的文件夹中.
在firefox和chrome中,如果你输入'hello'点击回车,'hi'点击回车,'goodbye'点击在文本搜索框中输入你得到正确的URL
本地主机/测试/测试/你好
和
本地主机/测试/检验/喜
和
本地主机/测试/检验/再见
repectively.
就是说你得到了
本地主机/测试/测试/你好
和
本地主机/测试/检验/检测/喜
和
本地主机/测试/检验/检测/检测/再见
分别
这里的问题是'测试'是预先的.如何阻止这种情况发生在ie.我无法在网上找到这个问题的答案.
html和jquery代码
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<base href="http://localhost/test/" />
<script src="jQuery.js"></script>
<script>
$(document).ready(function(){
$("#text-search").keyup(function(e){
if (e.keyCode == 13){
window.location.replace("testing/"+$('#text-search').val());
}
})
})
</script>
</head>
<body>
<input type='text' id='text-search'>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
的.htaccess
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^testing/(.+)$ /test/testing.php?string=$1 [L]
Run Code Online (Sandbox Code Playgroud)
你能帮我解决这个问题吗?非常感谢
Hal*_*yon 10
window.location不是一个字符串,我会非常小心地使用它 - 它实际上是一个Location对象.
也许这会对你有所帮助:
var href = window.location.href;
window.location = href.replace(/testing\/.*$/, "testing/"+$('#text-search').val());
Run Code Online (Sandbox Code Playgroud)
你也可以这样做:
var href = "" + window.location;
Run Code Online (Sandbox Code Playgroud)
强制进行字符串强制转换和值传递.
如果你这样设置: window.location.href = '/yourpage'
它会附加网址.避免使用//而不是/
所以它看起来像:window.location.href = '//yourpage'
| 归档时间: |
|
| 查看次数: |
9468 次 |
| 最近记录: |