使用 jQuery 进行 Mod_rewrite...为什么它不起作用?
我有一个页面,它使用 jQuery 提交表单并将数据附加回其中。但是,当使用 mod_rewrite 时,它不起作用。如果您访问的页面类似于 http://mydomain.com/file.php?string=m5cl
,那么它就可以工作。诡异的。
这是我的代码:
$(function() {
$('.error').hide();
$('input.text-input').css({backgroundColor:"#FFFFFF"});
$('input.text-input').focus(function(){
$(this).css({backgroundColor:"#FFDDAA"});
});
$('input.text-input').blur(function(){
$(this).css({backgroundColor:"#FFFFFF"});
});
$(".button").click(function() {
// validate and process form
// first hide any error messages
$('.error').hide();
var message = $("textarea#message").val();
var fullname = $("input#fullname").val();
var ticket_id = $("input#ticket_id").val();
var date = $("input#datee").val();
var picture_url = $("input#picture_url").val();
var userid = $("input#userid").val();
var user_status = $("input#user_status").val();
var sent = $("input#sent").val();
var dataString = 'message=' + message + '&user_id=' + userid + '&user_status=' + user_status + '&date=' + date + '&sent=' + sent + '&ticket_id=' + ticket_id;
//alert (dataString);return false;
$.ajax({
type: "POST",
url: "process.php",
data: dataString,
success: function() {
$(wrapperId).append("<div style='background-color:#dcd9d9;padding:15px;-moz-border-radius:8px;border-radius:8px; border:1px solid #d3d0d0;'><img src='" + $('#picture_url').val() + "' style='float:left;margin-right:15px;margin-top:-3px; border:3px solid #ffffff;' width='39'><div style='font-size:18px;font-family:Helvetica;color:#363636;font-weight:lighter;margin-bottom:2px;'>" + $('#fullname').val() + "</div><div style='font-size:14px;font-family:Helvetica;color:#363636;font-weight:lighter;text-align:justify;'>" + $('#datee').val() + "</div></div><div style='font-size:15px;color:#363636;line-height:18px;margin-top:15px;padding:0px 15px 0px 15px;text-align:justify;margin-bottom: 30px;'>" + $('#message').val() + "</div>");
}
});
return false;
});
});
runOnLoad(function(){
$("input#name").select().focus();
});
I have a page that uses jQuery to submit a form and append data back to it. However, it doesn't work when mod_rewrite is used. If you are on the page like this http://mydomain.com/file.php?string=m5cl
, then it will work. Weird.
Here's my code:
$(function() {
$('.error').hide();
$('input.text-input').css({backgroundColor:"#FFFFFF"});
$('input.text-input').focus(function(){
$(this).css({backgroundColor:"#FFDDAA"});
});
$('input.text-input').blur(function(){
$(this).css({backgroundColor:"#FFFFFF"});
});
$(".button").click(function() {
// validate and process form
// first hide any error messages
$('.error').hide();
var message = $("textarea#message").val();
var fullname = $("input#fullname").val();
var ticket_id = $("input#ticket_id").val();
var date = $("input#datee").val();
var picture_url = $("input#picture_url").val();
var userid = $("input#userid").val();
var user_status = $("input#user_status").val();
var sent = $("input#sent").val();
var dataString = 'message=' + message + '&user_id=' + userid + '&user_status=' + user_status + '&date=' + date + '&sent=' + sent + '&ticket_id=' + ticket_id;
//alert (dataString);return false;
$.ajax({
type: "POST",
url: "process.php",
data: dataString,
success: function() {
$(wrapperId).append("<div style='background-color:#dcd9d9;padding:15px;-moz-border-radius:8px;border-radius:8px; border:1px solid #d3d0d0;'><img src='" + $('#picture_url').val() + "' style='float:left;margin-right:15px;margin-top:-3px; border:3px solid #ffffff;' width='39'><div style='font-size:18px;font-family:Helvetica;color:#363636;font-weight:lighter;margin-bottom:2px;'>" + $('#fullname').val() + "</div><div style='font-size:14px;font-family:Helvetica;color:#363636;font-weight:lighter;text-align:justify;'>" + $('#datee').val() + "</div></div><div style='font-size:15px;color:#363636;line-height:18px;margin-top:15px;padding:0px 15px 0px 15px;text-align:justify;margin-bottom: 30px;'>" + $('#message').val() + "</div>");
}
});
return false;
});
});
runOnLoad(function(){
$("input#name").select().focus();
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不是您原来问题的答案,但这是一个关键的解决方案。
您不必执行所有这些操作:
如果所有这些内容都在
另外,由于您没有清理这些值,如果我在其中一个输入框中输入一个空格,您的 POST 请求将会终止,因为请求字符串将无效。
Not an answer to your original question, but it's a critical fix.
You don't have to do all this:
If all of these things are in a
<form>
element and each of those elements has aname=
attribute which is identical to the variable name (so it gets passed to the script properly), you can condense all of that, into this (yes, really):Also, since you aren't sanitizing the values, if I put a space into one of those input boxes, your POST request will die, as the request string will be invalid.
你试过这个吗?
Have you tried this?