views:

66

answers:

3

Hi all,

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="http://stackoverflow.com/questions/ask"&gt;

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: http://stackoverflow.com/
instead of
http://stackoverflow.com/questions/ask

I have tried using escape(whatContent), and encodeURI(whatContent), but they could not help,
the Alert box still showed me http://stackoverflow.com/
instead of
http://stackoverflow.com/questions/ask

I am not sure how to do with the URL data that contains some special characters in it.

+1  A: 

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.

Zane Edward Dockery
You **don't** have to be logged in to ask a question on SO, there's no such redirect. Simple to test, log out and try it. Besides, he's not making any request to SO, he's just passing text to a page that *happens* to be a URL.
Nick Craver
+3  A: 

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.

Jhong
+1  A: 

Hello kwokwai, 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? Kind regards, Benjamin.

benjamin