I'm making an Ajax call that sends a URL to a PHP script. Oftentimes these URLs are complex and contain special characters. If I don't encode the URL before sending, the PHP script works, but the URL's values are interpreted as my values (which is expected).
If I do encode a URL that doesn't contain special characters, like 'http://google.com' for example, the XMLHttpRequest sends my parameters to my PHP script as expected and everything works fine.
The issue is when I encode a URL that does contain special characters, like 'http://google.com?this=that&that=this' -- send() doesn't ever reach my PHP script. It just hangs indefinitely. No errors or anything. I'm stumped.
Here's what I'm working with:
function getContent(content, sumbittedUrl){
var postContent = encodeURIComponent(content);
var postUrl = encodeURIComponent(submittedUrl);
var postString = 'content=' + postContent + '&url_get=' + postUrl;
var httpRequest;
//create XMLHttpRequest
.
.
.
httpRequest.onreadystatechange = alertContents;
httpRequest.open('POST', 'php/my_php_script.php', true);
httpRequest.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
httpRequest.send(postString);
}
I'm a JavaScript novice so it's possible (likely, even) that I overlooked something that someone with more experience would spot quickly. Any help would be appreciated. Thanks.