簡體   English   中英

從其他域獲取圖像的原型ajax

[英]prototype ajax fetching images from other domain

我有兩條路徑:

a) localhost/firstapplication/

b) localhost/secondapplication/images

在firstapplication中,我對secondapplication/html/index.html進行了ajax請求。 例如,我獲取整個響應文本。

在secondapplication中有一些img標簽:

<img src="../images/testpicture.png" alt="test" />

我的問題:如果我添加整個responsetext文本,我的瀏覽器正在尋找圖像..鏈接是相對的,這意味着: firstapplication/images

但是我想要第二個應用程序的圖像。

有什么辦法可以使他們真正容易嗎? 還是我必須將每個img標記中src-attributes所有值從"../images"更改為固定路徑,例如"localhost/secondapplication/images/"

感謝你的支持。

我正在與prototype js 1.7一起工作,我更喜歡使用此框架的解決方案。 謝謝!

如果firstapplicationsecondapplication在不同的域上,則由於secondapplication 策略 ,AJAX將無法工作。 因此,對於您的映像問題,我沒有給出任何答復,因為一旦將其實時部署,您的代碼將無法正常工作。

我看到一些可能性

  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 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM