原型AJAX从其他域
提取图像I具有两条路径,如:原型AJAX从其他域
一个)localhost/firstapplication/
B)localhost/secondapplication/images
我做了Ajax的请求secondapplication/html/index.html
。例如我获取整个反应文本。
在secondapplication有一些IMG标签:
<img src="../images/testpicture.png" alt="test" />
我的问题:如果我追加整个responsetext
我的浏览器正在寻找的图像..链接是相对的,在至极表示:firstapplication/images
。
但我想要的第二个应用程序的图像。
有什么办法让他们真的很容易吗?或者是否必须将每个img标记中的src-attributes
的所有值从"../images"
更改为修复路径,如"localhost/secondapplication/images/"
?
感谢您的支持。
即时通讯工作与prototype js 1.7
,我会优先考虑这个框架的解决方案。谢谢!
如果firstapplication
和secondapplication
位于不同的域,AJAX将不会工作,因为Same Origin Policy。因此,我没有对你的图像问题做出回应,因为一旦实时部署,你的代码将无法工作。
我看到几个可能性
使用iframe,而不是AJAX。
让第二个域提供绝对URL。
-
当AJAX完成时操作URL。
new Ajax.Updater('secondapplication/html/index.html', 'ELEMENT_ID', { onSuccess: function(response){ var receiver = $(this.container.success); var otherDomain = 'http://localhost/secondapplication/'; var selector = '[src]:not([src^=/]):not([src^=http])'; receiver.select(selector).each(function(element) { element.src = otherDomain+element.readAttribute('src'); }); selector = '[href]:not([href^=/]):not([href^=http]):not([href^=#])'; receiver.select(selector).each(function(element) { element.href = otherDomain+element.readAttribute('href'); }); } }); // otherDomain must end in a solidus,/ // not tested
请不要iframes =( – 2011-02-26 01:42:31
否iframes ..我有机会让我知道代理,现在它的工作=) – eav 2011-02-27 21:02:53
看看这个JSONP W /'prototype' http://teamco-anthill.blogspot.com/2010/01/ajaxjsonrequest-is-jsonp-for.html – kjy112 2011-02-26 01:32:11