在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);
?>
doudui1850
doudui1850 示例不起作用,屏幕截图按钮甚至没有显示
一年多之前 回复
douhoulei4706
douhoulei4706 从该页面查看脚本,也许有帮助:coursesweb.net/javascript/...
一年多之前 回复
dongyixiu3110
dongyixiu3110 是的,它是冷融合,但我怎么知道它们是否兼容,或者服务器是否配置为处理php..这是我第一次使用php
一年多之前 回复
dqudtskm49788
dqudtskm49788 “在同一文件夹中找到test.cfm和export.php文件”-您确定服务器配置为解析并执行这两种类型吗?因为“方法不允许”通常是当您尝试将数据POST到URL时服务器认为是“静态”的,而不是开始的动态脚本。
一年多之前 回复
dqiz20794
dqiz20794 不得不查找.cfm扩展名。看起来像是ColdFusion?这与PHP兼容吗?
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问