对包含一些特殊字符的URL的处理方式 [英] What you would do to a URL that contains some special characters
问题描述
我正在使用cakePHP 1.26
我得到了一个包含URL的输入文本框,我想提交该URL并使用Jquery AJAX将其存储在数据库中。
I am using cakePHP 1.26
I got an Input Text box which contains a URL and I want to submit the URL and stored it in the Database using Jquery AJAX.
以下是HTML部分:
Here is the HTML part:
<input type="text" id="testing" value="https://stackoverflow.com/questions/ask">
这是JQuery的一部分:
This is the JQuery part:
var whatContent=$("#testing").val();
var curl="http://localhost:8080/test/grab/"+whatContent;
$.ajax({
type: "POST",
url: curl,
success: function(data) {
alert(data);}
});
这是控制器中操作的代码:
This is the code for the Action in the Controller:
function grab($w=null){
if($w!=null){
return $w;
}
}
代码有效,我可以看到警报消息弹出向上,但显示:
https://stackoverflow.com/
而不是
https://stackoverflow.com/questions/ask
The code worked and I could see the Alert Message pop up, but it showed:
https://stackoverflow.com/
instead of
https://stackoverflow.com/questions/ask
我曾尝试使用转义(whatContent)和encodeURI(whatContent),但它们无济于事,
警报框仍向我显示
https://stackoverflow.com/
代替了
https://stackoverflow.com/questions/ask
I have tried using escape(whatContent), and encodeURI(whatContent), but they could not help,
the Alert box still showed me
https://stackoverflow.com/
instead of
https://stackoverflow.com/questions/ask
我不确定该怎么做
I am not sure how to do with the URL data that contains some special characters in it.
推荐答案
也许是 debug($ w)
在您的控制器操作中可能会显示一些内容。
除了目标地址之外,其他输入的输出是什么?
Maybe a debug($w)
in you controller action could reveal something.
What is the output of other input than the address that is your goal?
这篇关于对包含一些特殊字符的URL的处理方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!