What you would do to a URL that contains some special characters

馋奶兔 提交于 2019-12-11 14:05:57

问题


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.


回答1:


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?




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/3382061/what-you-would-do-to-a-url-that-contains-some-special-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!