Search code examples
jqueryhtmlajaxmobiletitanium

jquery loading another website with .ajax replace img src


i try to load a div from another website but when i load, img src is not full path so i can't see images so i need to replace them with full true path. i try but it does'nt work. How can i solve my proble?

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script type="text/javascript" src="jquery.min.js"></script>
</head>

    <div id="pull"></div>
 <script>

   $.ajax({
       url: "http://www.example.com",
       cache: false,type: "POST"
       }).done(function( html ) {
           var news=$(html).find('.news_slider');
           $(news).find('img').attr("src",$(news).find('img').attr("src").
           replace(".images/","http://www.example.com/images/"));
          $("#pull").append(haberler);
       });
</script>
</body>
</html>

And i tested it on my android mobile app which is programmed with titanium mobile but webview ui rendered it with wrong screen resolution. İt was very big view. How can i solve it? my titanium code is like that:

var win5 = Titanium.UI.createWindow({
    title : 'Servisler',
    backgroundColor : '#CEE6F2'
 });
var tab5 = Titanium.UI.createTab({
icon : 'duyuru.png',
title : 'Servisler',
window : win5
 });

var servis = Ti.UI.createWebView({
url : 'servis.html',//upside code is servis.html
 width:'100%'
 });
win5.add(servis);

thanks your interests..


Solution

  • You shouldn't be able to access the other site with AJAX due to cross domain restrictions.

    To answer how to change all the images:

    You need to loop over each image which can be done several ways using each or attr() has a function argument that will do it also

    $(news).find('img').attr("src", function( i, SRC){
         return SRC.replace(".images/","http://www.example.com/images/");
    });
    

    API refernce: http://api.jquery.com/attr