duanjun7801 2013-06-25 01:47
浏览 84
已采纳

<img>没有使用jQuery刷新

I am developing with xhtml, LAMP and jQuery 2.0.2 on Debian 7.0.0.

I am using the following php-generated element

echo "<img id=\"displayImageID\" src=\"" . $DisplayFileName . "\" alt=\"Background\" style=\"margin:10px 0px 10px 5px\"/>";

I am hoping to change it to a different color look up table when the used clicks on a radio button. In order to do this, I use the following code

    jQuery.ajax({
    type: "POST",
    url: "DisplayParameters.php",
    data: { LUT:lut }
    }).done(function( result ) {
    $("#msg").html( " Ajax called" );
    });        

with the following code in DisplayParameters.php

    $LUT=$_POST['LUT'];
    $Executable="Executables/changeLUT";
    $DisplayImageName="images/display.png";
    $Str=$Executable . " -t " . $LUT" . " -o " . $DisplayImageName;

    $output=exec($Str, $dummy, $returnValue);

    echo "<script language=\"JavaScript\">";
    echo "d = new Date();";
    echo "jQuery('#displayImageID').attr('src', '" . $DisplayImageName . "?'+d.getTime());";
    echo "</script>";
}

to update the image and to reload it into the image element but nothing happens until I refresh the whole page with the Firefox "Reload current page".

I had thought that maybe, due to the asynchronous nature of Ajax, the image is getting loaded before it is replaced by a new image with the same name but different color LUT. However, if this were the case, I would expect the new LUT image to eventually be loaded if I keep clicking on radio buttons after the image that is saved to the disk is changed. This is not the case. I do not get a new image until I reload the page.

  • 写回答

1条回答 默认 最新

  • doutan5337 2013-06-25 01:55
    关注

    Try this:

    JS

    jQuery.ajax({
           type: "POST",
           url: "DisplayParameters.php",
           data: { LUT:lut },
           cache: false                               //CHANGED
    }).done(function( result ) {
           $("#msg").html( " Ajax called... and returned " + result );
           //('#displayImageID').attr('src', result);   
           ('#displayImageID').attr('src', result+'?'+$.now());   //CHANGED
    });    
    

    PHP

    $LUT=$_POST['LUT'];
    $Executable="Executables/changeLUT";
    $DisplayImageName="images/display.png";
    $Str=$Executable . " -t " . $LUT" . " -o " . $DisplayImageName;
    
    $output=exec($Str, $dummy, $returnValue);
    
    echo $DisplayImageName;                         //CHANGED
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容