Javascript 使用encodeURIcomponent并在服务器端对其进行解码
我使用encodeURIcomponent向服务器发送了一个url作为请求参数的一部分Javascript 使用encodeURIcomponent并在服务器端对其进行解码,javascript,ruby-on-rails,encodeuricomponent,Javascript,Ruby On Rails,Encodeuricomponent,我使用encodeURIcomponent向服务器发送了一个url作为请求参数的一部分 http://www.regis.edu/regisgpcd.asp?sctn=cpedcn&p1=ap&p2=EDFD&p3=cd3Dcd&_=1332612418587 这是服务器看到的内容: http://www.regis.edu/regisgpcd.asp?sctn=cpedcn&p1=ap&p2=EDFD
http://www.regis.edu/regisgpcd.asp?sctn=cpedcn&p1=ap&p2=EDFD&p3=cd3Dcd&_=1332612418587
这是服务器看到的内容:
http://www.regis.edu/regisgpcd.asp?sctn=cpedcn&p1=ap&p2=EDFD&p3=cd
虽然我以前用encodeURIcomponent再次将其插入数据库,但我得到一个错误,在数据库中找不到它
此url的格式如下所示,尽管我再次将其插入了encodeURIcomponent之后。我猜mysql在将其插入列之前将其转换为常规类型
http://www.regis.edu/regisgpcd.asp?sctn=cpedcn&p1=ap&p2=EDFD&p3=cd
我怎样才能解决这个问题?有什么想法吗
这是我的插入代码:
$.ajax({
type : "GET",
url : '/tree/insertResult/?url=' + encodeURIComponent(url) + '&title=' + encodeURIComponent(title)+'&folder='+folderName+'&snippet='+encodeURIComponent(snippet),
cache : false,
success : function(res) {
if(res == "F")
notification("Operation Failed", "You have that bookmark in that folder!");
else{
folderName = res;
notification("Operation Suceeded", "Bookmark has been created.");
updateFolderContent(url, title, folderName, snippet);//it is in _filetree_javascript.html.erb
}
},
error : function(x, y, z) {
alert(x.responseText);
}
});
}
这是我的提取代码:
$.ajax({
type : "GET",
url : '/tree/deleteResult/?title='+encodeURIComponent(title)+"&url="+encodeURIComponent(url),
cache : false,
success : function(res) {
if(res == "F") //if F is returned from server it means "There is a folder with same name"
notification("Operation Failed", "Bookmark cannot be deleted! Sorry :(");
else
notification("Operation Succeed", "Bookmark've been deleted.");
deleteResult(domObj);
},
error : function(x, y, z) {
alert(x.responseText);
}
});
}
我通过在服务器上解码字符串来解决这个问题。我在rails中使用了CGI gem
CGI::unescapeHTML(url)
尝试在ajax设置对象中设置
cache:false
。设置为什么?是或否…url的哪个参数用于删除记录?url是一个常规url http://bla blaHmm..我的建议是,在插入数据(通过ajax调用)时,请查看数据库表中插入的数据行。当删除时(通过ajax调用),查看“title”和“url”是否与之前存储的相同。祝你好运