-2

I want to display image before the link returned through php. Below is the ajax code

$.ajax({ //Make the Ajax Request
    type: "POST",
    url: "dbtryout2_2.php",
    data: datastr,
    success: function (arrayphp) {
        //how to display image before this link
        var link = $('<a href="#" class="my-class">' + arrayphp + '</a>');
        $(".searchby .searchlist").append(link);

    }
});
Arturs
  • 1,258
  • 5
  • 21
  • 28

1 Answers1

0

Just append the image before the link.

$.ajax({ //Make the Ajax Request
    type: "POST",
    url: "dbtryout2_2.php",
    data: datastr,
    success: function (arrayphp) {
        //how to display image before this link
        var link = $('' + arrayphp + '');
        var image = "<img src='http://www.yourdomain.com/iamge.png' alt='' />"
        $(".searchby .searchlist").append(image).append(link);

    }
});
Arturs
  • 1,258
  • 5
  • 21
  • 28
Laurynas Mališauskas
  • 1,909
  • 1
  • 19
  • 34
  • @ LAURYNAS iam displaying links one by one through php from inside a loop and i want the image to be displayed before each link but here the image is getting displayed before only the first link and not getting displayed before rest of the links – Nitish kumar thakur Aug 27 '13 at 18:55
  • $(".searchby .searchlist a").prepend(image); that should do the trick – Laurynas Mališauskas Aug 28 '13 at 09:19
  • @ LAURYNAS i have edited ur code to wat my actual code is.The trick u told is not working.I have described my problem in comment – Nitish kumar thakur Aug 28 '13 at 13:53
  • you must give me more details on what is returned by the ajax call. i can not help you if i do not know what code is returned there and what is your html – Laurynas Mališauskas Aug 29 '13 at 07:49
  • @ Laurynas now iam clear with my problem.You see the arrayphp argument in my code.I was thinking that php sends one value at a time .But actually php sends all the elements that are to be echoed one by one from inside a loop at once to the arrayphp argument thats why all the elements are getting displayed as one link and the image is getting dispalyed only once – Nitish kumar thakur Aug 29 '13 at 19:19