I'm trying to get through $.get()
function the content of an HTML page. This page contains in its filename the special character +:
mypage+v1.html
Here is how I'm trying to get the content:
$.get("mypage+v1.html", function(data){
alert(data);
});
This code works and runs fine locally, it correctly retrieves the content. As soon as I move it to a web server, it stops to work and the ajax call returns 404 Not found error.
I tried to replace the + with an _ both in the script and in the filename and it works, but I need to keep the plus sign.. I tried to use encodeURI()
$.get(encodeURI("mypage+v1.html"), function(data){
alert(data);
});
and also to manually replace + with %2B
var url = "mypage+v1.html".replace("+", "%2B");
$.get(url , function(data){
alert(data);
});
but it didn't do the trick..
Using
$.get(encodeURIComponent("mypage+v1.html"), function(data){
alert(data);
});
throws the following error:
GET http://.../mypage%2Bv1.html 404 (not found)
even with the encoded url it does not work.
Side note: I'm successfully retrieving other pages with
$.load("pagename.html #divToAppendTo", function(res, stat, xhr){
....
});
I need to use $.get
because I need to manipulate and slice the file content before I append these slices in different portions of my original HTML file. I tested the $.load()
call and it's using Request method: GET, this way I know that the folder is accessible..
Any other idea?
Thanks