• Whenever I try to search for images, Google Chrome console logs this error:

    Uncaught TypeError: Cannot read property 'small' of undefined
        at Object.unsplash.displayImages (unsplash.js:112)
        at Object.success (unsplash.js:68)
        at i (load-scripts.php:2)
        at Object.fireWith [as resolveWith] (load-scripts.php:2)
        at y (load-scripts.php:4)
        at XMLHttpRequest.c (load-scripts.php:4)

    And the search never finishes.

    Milan

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Darren Cooney

    (@dcooney)

    Hi @gdragon,
    I’m not able to recreate this issue in 3 unique environments… Maybe something was up with the Unsplash API at the time?

    Thread Starter Milan Petrovic

    (@gdragon)

    When I click on Search (with no keyword), I get the results (latest of features images or something). And, if I click on the example search (coffee + woman), it also works. But, if I enter keyword: ‘chart’, I get the error.

    I have inspected AJAX results returned from Unspash, and for the ‘chart’ I see 3 results, so most likely problem is that your code fails to properly parse the results, and it assumes that some element is present, even if it is not (property ‘small’).

    Plugin Author Darren Cooney

    (@dcooney)

    Maybe it could have better validation, but even with that said searching for chart doesn’t produce any errors for me.

    Thread Starter Milan Petrovic

    (@gdragon)

    I tried several times, all the same. All searches return the error, except the ‘coffee + woman’. But, results are always returned from Unsplash, and all results have ‘urls’ ‘small’ property. I did some debugging, and in some cases (on line 108 in unspash.js), photos array contains photos and one extra element as a function. Where that comes from, I have not gone too deep to find out. But, you just need to check if the element of photos is actually a photo element (object with urls propery), and it would be OK.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘JavaScript error when searching for images’ is closed to new replies.