如何通过ajax解析重定向的url
首先,我很抱歉我的英语不好,但我希望你能明白我的意思。
我需要获取服务器重定向的网址,例如
http://exam.ple/get/23456 转到-> http://exam.ple/full_url/content?id=34567
我正在尝试做在ajax中,但很奇怪,只有当浏览器加载缩短的url时,这个东西才起作用,当我尝试在ajax中访问该url时,我得到了谷歌主页作为结果。
我对页面内容不感兴趣,只对 url 感兴趣,跨域策略不是问题。 也许使用 php 代理会更容易,但我试图避免服务器端代码
注意:缩短的链接受到 robots.txt 的保护,不会被 robots.txt 抓取
提前致谢。
编辑 我没有发布任何代码,因为根本不起作用,我已经尝试了很多方法,
$.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);
}
但正如
var req = new XMLHttpRequest();
req.onreadystatechange = function() { ..........
我所说,响应总是相同的,谷歌主页。 不,不想将用户重定向到任何地方,只需要 url 数据即可使用它。
First at all sorry for my poor english, but i might 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您发布您的代码,那就太好了。但是,这里有一些提示:
1) 尝试在 ajax 调用中使用非完整 url
2) 您需要在客户端上重定向吗?如果是这样,您可以使用:
希望这会有所帮助。如果没有,请发布您的代码并稍微解释一下,以便我们可以更好地帮助您。干杯
It would be good if you post your code. However, here are some tips:
1) Try using non-full url in your ajax call
2) Do you need to redirect on the client? if so, you can use:
Hope this helps. If not, please post your code and explain it a little bit so we can help you better. Cheers