0

I have some errors in my extension. I have this code that do a find() on an external page:

$.ajax({
    url: 'http://www.subspedia.tv/traduzioni.php',
    success: function(data) {
        $(data).find('.itemListaSerie').each(function() {
            console.log($(this).attr('title'));
        });
    }
});

The find function work correctly but after the result I have a lot of errors that say "File not found" on all images in the page that I'm doing the request. The screen show my result: enter image description here

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
master94ga
  • 53
  • 2
  • 8
  • 1
    I'm assuming you're appending the HTML returned in the request to the page, if so the paths to the images are incorrect based on the current path of the page. You need to amend the paths to find the correct files. There's no specific issue to fix given the code you've provided. – Rory McCrossan Feb 14 '16 at 15:20
  • Is `data` a valid jquery obejct? – ashfaq.p Feb 14 '16 at 15:22
  • @RoryMcCrossan Yes, I append "$(this).attr('title') to the page. I don't need the image but only the title that I correctly get it, I need to exclude the images. – master94ga Feb 14 '16 at 15:31

2 Answers2

0

You need to post process the relate links like immagini/serie/covers/33.png for each of the images, and convert them into something like

http://www.subspedia.tv/immagini/serie/covers/33.png

instead of using it as is

EDIT: The images loaded are probably due to the $(data). If you need only the titles, then you should replace the src of all the tags before $(data)

success: function(data) {
    var strippedData = data.replace(/src='(?:[^'\/]*\/)*([^']+)'/g, "");
    $(strippedData).find('.itemListaSerie').each(function() {
        console.log($(this).attr('title'));
    });

Credit to @Gumbo for his answer on regex for matching src. Note, this will remove all src attributes in the page

Community
  • 1
  • 1
Obsidian
  • 515
  • 3
  • 10
0

After your success function, using $(data) you create an element that contain all the html from http://www.subspedia.tv/traduzioni.php so, the document is looking for all the script, css and the images included in that page. try to replace all the img as words in data as string and then call $(data).find....

Hope this helps you! Anche se mi sarei spiegato meglio in Italiano ;)

Vixed
  • 3,429
  • 5
  • 37
  • 68