dongzhao1930 2014-09-24 19:09
浏览 983
已采纳

从AJAX请求更改图像src

I have been trying a lot of different ways to make a change on a image src from a AJAX Requset, the new URL is retrived from an AJAX call, with the Developer Tools i visualized data the returning variable 'DATA' have the expected URL but the image SRC get this:

"atrk.js-; var s = document.getElementsByTagName('script')[0];s.parentNode"


The AJAX Request:

$.post("readurl.php",function(data){
      $("#imagen").attr("src",data);     
 });

The HTML Element:

<img id="imagen" src="old_pic.png">

The PHP file:

<?php
$xml=simplexml_load_file("links.xml");
echo $xml->URL_one;
?>

I hope someone can help me.

Thanks in advance!

  • 写回答

1条回答 默认 最新

  • ds261634878 2014-09-24 20:34
    关注

    try to use prop function:

    $("#imagen").prop("src",data); 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?