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

从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); 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 WPF使用Canvas绘制矢量图问题
  • ¥15 用三极管设计一个单管共射放大电路
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架