我通过使用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&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);
}
});
}
答案 0 :(得分:0)
我通过解码服务器上的字符串来解决这个问题。我在rails中使用了CGI gem
CGI::unescapeHTML(url)