我正在使用jQuery Autocomplete(从数据库中获取值)并从数据库中向用户显示结果。搜索结果是可点击的,当它们点击时,它们被发送到名为product_display.php的页面,其中id为请求参数。 因此例如,这将是这样的: - ?product_display.php ID = 2Htaccess URL重写异常行为
在product_display.php页,有3单选按钮和3点形成(每个单选按钮,则在无线电选择时动态地打开)。每个表单都有一个单独的提交按钮。点击提交后,它会进入不同的页面,并打印一个名为cond的隐藏变量的值。
一切工作正常,直到我在我的htaccess文件出台一个URL重写,以CONVER * product_display.php?ID = 2 *至/产品/ 2
当这个URL重写走进工作,结果不好。只要单击与任何单选按钮有关的任何表单的提交按钮,它就会再次显示product_display页面上的选项(但标题显示不同的页面)。 这怎么解决。
jQuery Auto Complete。
<script>
$(function() {
function log(message) {
$("<div>").text(message).prependTo("#log");
$("#log").scrollTop(0);
}
$("#birds").autocomplete({
source: "search.php",
minLength: 2,
select: function(event, ui) {
log(ui.item ? "Selected: " + ui.item.value + " aka " + ui.item.label :
"Nothing selected, input was " + this.actor);
window.location.href = './products/' + ui.item.value;
//window.location.href = 'product_display.php?id=' + ui.item.value;
// document.testForm.action = "pretravel.php?id="+ui.item.value;
//document.testForm.submit();
}
});
});
products_display.php
<div id="credit-card">
<section id="content">
<input type="radio" id="radio1" name="radios" value="radio1" checked>
<label for="radio1">Working</label>
<input type="radio" id="radio2" name="radios" value="radio2">
<label for="radio2">Working - Damaged</label>
<input type="radio" id="radio3" name="radios" value="radio3">
<label for="radio3">Not Working</label>
<form action="offer_show.php" method="post" id="working">
<input type="hidden" name="cond" value="working" id="cond">
<input type="submit" name="submit">
</form>
<form action="offer_show.php" method="post" id="workingdamaged">
DEbit Card payment here
<input type="hidden" name="cond" value="workingdamaged" id="cond">
<input type="submit" name="submit">
</form>
<form action="offer_show.php" method="post" id="nonworking">
<input type="hidden" name="cond" value="damaged" id="cond">
<input type="submit" name="submit">
</form>
</section>
</div>
</body>
<script type="text/javascript">
var radios = document.getElementsByName("radios");
var working = document.getElementById("working");
var workingdamaged = document.getElementById("workingdamaged");
var nonworking = document.getElementById("nonworking");
working.style.display = 'block'; // show
workingdamaged.style.display = 'none';
nonworking.style.display = 'none';// hide
for(var i = 0; i < radios.length; i++) {
radios[i].onclick = function() {
var val = this.value;
if(val == 'radio1')
{
working.style.display = 'block';
workingdamaged.style.display = 'none';
nonworking.style.display = 'none';
}
else if(val == 'radio2')
{
working.style.display = 'none';
workingdamaged.style.display = 'block';
nonworking.style.display = 'none';
}
else if(val == 'radio3')
{
working.style.display = 'none';
workingdamaged.style.display = 'none';
nonworking.style.display = 'block';
}
}
}
</script>
htaccess的
RewriteRule ^products/(.+)$ product_display.php?id=$1 [L,QSA]
offer_show.php(这在点击后打开提交页面)
<?php
echo $_REQUEST['cond'];
?>
不是什么大不了的,但你应该改变你的RewriteRule到这个(接近开始):'^ products /(\ d +)$'只允许ID字段中的数字。语义上正确,并有助于再次保护SQL注入,因为您不能只使用数字写入注入码。 –
工作完美。 谢谢你完全阅读这篇文章。我只是想知道是否有人会经历这么长的一段时间:) – Ankur
等等,是否解决了这个问题?如果是这样,我会添加它作为答案。 –