-1

I have an ajax call in jQuery which returns a set of values: p1, p2 ... pn. These contain strings of a path and filename for displaying images. ie the img src value.

I want to loop through these n values ( i = 1 to n ) something like [pseudo] :

$("#photo_" + i).html( '<img src="' + data.p + i + '">' );

The selector works fine .. it's the img src I am having problems building.

Upland
  • 691
  • 3
  • 8
  • 18

1 Answers1

2

You need to change data.p + i to data["p" + i]

Change

$("#photo_" + i).html( '<img src="' + data.p + i + '">' );

To

$("#photo_" + i).html( '<img src="' + data["p" + i] + '">' );
Adil
  • 146,340
  • 25
  • 209
  • 204