What you would do to a URL that contains some special characters
I am using cakePHP 1.26
I got an Input Text box which contains a URL and I want to submit the URL开发者_如何学Python 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/askI 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/askI am not sure how to do with the URL data that contains some special characters in it.
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.
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?
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.
精彩评论