user1041170
user1041170

Reputation:

Change img src using jQuery without refresh?

How can I change img src using jQuery without refresh? src is pulled from MySQL

Code:

<li><a><img src="pic1.jpg" /></a></li>
<li><a><img src="pic2.jpg" /></a></li>
<li><a><img src="pic3.jpg" /></a></li>
<li><a><img src="pic4.jpg" /></a></li>
<li><a><img src="pic5.jpg" /></a></li>

Upvotes: 0

Views: 155

Answers (1)

mwl
mwl

Reputation: 1488

You need to use $.ajax: http://api.jquery.com/jQuery.ajax/ and .attr(): http://api.jquery.com/attr/

Example:

$.ajax({
  method: "POST",
  url: "foo.php"
})
.done(function(data) {
  $('img').attr('src', data);
});

Upvotes: 1

Related Questions