How to resolve a redirected url via ajax
First at all sorry for my poor english, but i m开发者_JAVA百科ight that you can understand what i mean.
I need to get the url redirected by a server, for example
http://exam.ple/get/23456 turns to -> http://exam.ple/full_url/content?id=34567
im trying to do that in ajax, but is weird, the thing only works when the shorten url is loaded by the browser, when i try to access that url in ajax, i get the google homepage as result.
Im not interested in the content of the page, just the url, and the cross-domain policies aren't the problem. Maybe would be easyer using a php proxy but im trying to avoid server side codes
Note: the shorten links are protected from scraping by robots.txt
Thanks in advance.
EDIT I didn't post any codes cause nothing worked at all, i've tryed many ways,
$.ajax({
url: "http://exam.ple/get/23456",
...
});
var request = new air.URLRequest("http://exam.ple/get/23456");
var loader = new air.URLLoader();
loader.addEventListener(air.Event.COMPLETE,completeHandler);
loader.load(request);
}
function completeHandler(event){
var dataXML = event.target.data;
air.trace(dataXML);
}
Also trought
var req = new XMLHttpRequest();
req.onreadystatechange = function() { ..........
But as i said, the response is always the same, the google homepage. And no, dont want to redirect the user to anywhere, just need the url data to work with it.
It would be good if you post your code. However, here are some tips:
1) Try using non-full url in your ajax call
$.ajax({
url: "/get/23456",
...
});
2) Do you need to redirect on the client? if so, you can use:
location.href = "/full_url/content?id=34567";
Hope this helps. If not, please post your code and explain it a little bit so we can help you better. Cheers
精彩评论