您将对包含某些特殊字符的 URL 执行什么操作
我正在使用 cakePHP 1.26
我有一个包含 URL 的输入文本框,我想提交该 URL 并使用 Jquery AJAX 将其存储在数据库中。
这是 HTML 部分:
<input type="text" id="testing" value="https://stackoverflow.com/questions/ask">
这是 JQuery 部分:
var whatContent=$("#testing").val();
var curl="http://localhost:8080/test/grab/"+whatContent;
$.ajax({
type: "POST",
url: curl,
success: function(data) {
alert(data);}
});
这是控制器中操作的代码:
function grab($w=null){
if($w!=null){
return $w;
}
}
代码有效,我可以看到弹出警报消息,但它显示: https://stackoverflow.com/
而不是
https://stackoverflow.com/questions/ask
我尝试过使用 escape(whatContent) 和encodeURI(whatContent) ,但他们无能为力,
警报框仍然向我显示 https://stackoverflow.com/
而不是
https://stackoverflow.com/questions/ask
我不知道如何处理包含某些内容的 URL 数据其中的特殊字符。
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.
Here is the HTML part:
<input type="text" id="testing" value="https://stackoverflow.com/questions/ask">
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;
}
}
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
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
执行 POST 请求似乎很有趣,但将数据附加到 URL 上。用户可以使用 GET,然后
escape(whatContent)
,或者使用 POST,并将 WhatContent 作为数据参数传递。Seems funny to do a POST request, but append the data onto the URL. Either user GET, and
escape(whatContent)
, or use POST, and pass whatContent as the data parameter.也许控制器操作中的
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?
您是否必须登录 SO 才能提问? SO 只是将您的请求重定向到主页,这是有道理的。
Don't you have to be logged into SO to ask a question? It would make sense that SO is just redirecting your request to the main page.