Requirements Analysis:
Enables the display of images on a Web page. The picture content has changed because the read picture name is the same. Use of the Internet requires that the browser does not cache the operation does not take effect
<METAhttp-equiv= "Pragma"CONTENT= "No-cache"> <METAhttp-equiv= "Cache-control"CONTENT= "No-cache, must-revalidate"> <METAhttp-equiv= "Expires"CONTENT= "0"> <MetaCharSet= "Utf-8"> <METAhttp-equiv= "Expires"CONTENT= "Wed, 1997 08:21:57 GMT"> <METAhttp-equiv= "Expires"CONTENT= "0">
Later, using AJAX to request data, directly from the back-end to read the picture content and return to the front end, so as to achieve the latest picture data display
Front-End AJAX requests:
$.ajax ({url: ' index.php ', type: ' POST ', DataType: ' JSON ', data: { Mode: '<?= $Mode?>', ID: '<?= $idVal;?>'} '). Success (function (data) {//Console.log (data); $.each (Data,function (name,value) {//Console.log (name); Console.log (value); $ ("#sm_image" +name). attr ("src", "data:image/png;base64," +value); }). Done (function (data) {Console.log ("success"); $ ("Sm_image"). attr ("src", "data:image/png;base64," +data); echo}). Fail (function (data) {Console.log (data); Console.log ("error"); }). Always (function () {Console.log ("complete"); });
Background PHP parsing and return:
<?PHPif($_post) { Switch($_post[' Mode ']) { Case1://Print_r ($_post[' id '); $IDARR=Explode(",",$_post[' ID ']); $jsonStr= "{"; for($i= 0;$i<Count($IDARR) ;$i++) { $img=Base64_encode(file_get_contents("/web/image/image_id".$IDARR[$i].". png)); $jsonStr.= "\"".$IDARR[$i]." \":\"$img\","; } $jsonStr=substr($jsonStr, 0,-1); $jsonStr.= "}"; Echo $jsonStr; Break; Case2:$id=$_post[' ID ']; $img=Base64_encode(file_get_contents("/web/image/image_id".$id.". png)); Echo‘{"‘.$id.‘":"‘.$img.‘"}‘;//read image data and encode base64 Break; default: Break; } }?>
Ajax requests multiple picture data