dongtiao0657 2019-03-21 12:53
浏览 54

在javascript中从ajax调用PHP

trying to save page capture using html2canvas the captue is done but the save is not i am getting "method not allowed error" if i comment everything except for the php call, i get "not found" error i am a newbie to all this, may be i am missing something

both files test.cfm and export.php are found in the same folder cfsanad

test.cfm

<!doctype html>
<html>
<head>
<script type="text/javascript" src="SCRIPTS/es6-promise.min.js"></script>
<script type="text/javascript" src="SCRIPTS/es6-promise.auto.min.js"> </script>
<script type="text/javascript" src="SCRIPTS/html2canvas.js"></script>
<script type="text/javascript" src="SCRIPTS/jquery-2.1.0.min.js"></script>
</head>
<body>
<h1>Take screenshot of webpage with html2canvas</h1>
<div class="container" id='container' >
 hi
 bye
</div>
<input type='button' id='but_screenshot' value='save screenshot' onclick='exportAndSaveCanvas();'><br/>
<br/>
<!-- Script -->
<script type='text/javascript'>
function exportAndSaveCanvas()  {
try
{
   html2canvas(document.body).then(function(canvas) {

     document.body.appendChild(canvas);

     // Get base64URL
     var base64URL = canvas.toDataURL('image/jpeg').replace('image/jpeg', 'image/octet-stream');

     // AJAX request
     $.ajax({
       type: 'POST',
        url: 'export.php',
        data: {image: base64URL},
        success: function(data){
           alert('Upload successfully');
           },
        error: function(XMLHttpRequest, textStatus, errorThrown) { 
                alert("Status: " + textStatus+ "
Error: " + errorThrown);
        }
     }); //ajax

   }); //html2canvas
 }
 catch(err)
{
    alert('DBconnect: '+err.message);
    return 'err';
}
} // End exportAndSaveCanvas()
</script>

</body>
</html>

export.php

<?php
$message = "in php";
echo "<script type='text/javascript'>alert('$message');</script>";

$image = $_POST['image'];

$location = "IMAGES/";

$image_parts = explode(";base64,", $image);

$image_base64 = base64_decode($image_parts[1]);

$filename = "screenshot_".uniqid().'.png';

$file = $location . $filename;
file_put_contents($file, $image_base64);
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 PADS Logic 原理图
    • ¥15 PADS Logic 图标
    • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
    • ¥20 气象站点数据求取中~
    • ¥15 如何获取APP内弹出的网址链接
    • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
    • ¥50 STM32单片机传感器读取错误
    • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
    • ¥15 机器人轨迹规划相关问题
    • ¥15 word样式右侧翻页键消失