Reputation: 3321
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.
Upvotes: 0
Views: 366
Reputation: 2185
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?
Upvotes: 1
Reputation: 2752
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.
Upvotes: 3
Reputation: 3981
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.
Upvotes: 1