原型AJAX从其他域

问题描述:

提取图像I具有两条路径,如:原型AJAX从其他域

一个)localhost/firstapplication/

B)localhost/secondapplication/images

在firstapplication

我做了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,我会优先考虑这个框架的解决方案。谢谢!

+0

看看这个JSONP W /'prototype' http://teamco-anthill.blogspot.com/2010/01/ajaxjsonrequest-is-jsonp-for.html – kjy112 2011-02-26 01:32:11

如果firstapplicationsecondapplication位于不同的域,AJAX将不会工作,因为Same Origin Policy。因此,我没有对你的图像问题做出回应,因为一旦实时部署,你的代码将无法工作。

+0

你可以做JSONP解决dif域政策问题 – kjy112 2011-02-25 14:38:10

+0

是啊mhitza我知道,那是我最初的问题...我怎么能使它工作...与我以前注意到的插件是否有可能呢...和jsonp – eav 2011-02-27 21:03:48

我看到几个可能性

  1. 使用iframe,而不是AJAX。

  2. 让第二个域提供绝对URL。

  3. 当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 
    
+0

请不要iframes =( – 2011-02-26 01:42:31

+0

否iframes ..我有机会让我知道代理,现在它的工作=) – eav 2011-02-27 21:02:53