第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用帶有數(shù)據(jù)的ajax重定向php頁面?

如何使用帶有數(shù)據(jù)的ajax重定向php頁面?

PHP
元芳怎么了 2022-09-12 10:54:14
    我知道這里有很多與我的標(biāo)題相同的問題,但我無法使用為他們提供的答案來解決我的問題。該程序應(yīng)該在截取谷歌地圖的屏幕截圖后將頁面重定向到OCR結(jié)果。發(fā)生的事情是,我只能通過網(wǎng)絡(luò)>過程.php >預(yù)覽來查看結(jié)果。我也嘗試在ajax上使用,但它只會導(dǎo)致頁面出現(xiàn)很多錯誤,因為缺少數(shù)據(jù)。以下是索引.phpwindow.location.href = "your-url-to-redirect-to";<body><input type='button' class="btn btn-success" id='but_screenshot' value='Take screenshot' onclick='screenshot();'><br/><script type="text/javascript">    function screenshot() {        var transform = $(".gm-style>div:first>div:first>div:last>div").css("transform");        var comp = transform.split(",")        var mapleft = parseFloat(comp[4])        var maptop = parseFloat(comp[5])        $(".gm-style>div:first>div:first>div:last>div").css({             "transform":"none",            "left":mapleft,            "top":maptop,        });        html2canvas(document.getElementById('map'), {            useCORS: true        }).        then(function(canvas) {                var base64URL = canvas.toDataURL('image/jpeg').replace('image/jpeg', 'image/octet-stream');                $.ajax({                    url: 'processing.php',                    type: 'post',                    data: {image: base64URL},                    success: function(data){                        console.log('Upload successfully');                    }                });            }        );    }</script></body>這是processing.php<?php// upload screenshot$image = $_POST['image'];$location = "uploads/";$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);// end
查看完整描述

1 回答

?
慕后森

TA貢獻(xiàn)1802條經(jīng)驗 獲得超5個贊

    我知道這里有很多與我的標(biāo)題相同的問題,但我無法使用為他們提供的答案來解決我的問題。

該程序應(yīng)該在截取谷歌地圖的屏幕截圖后將頁面重定向到OCR結(jié)果。發(fā)生的事情是,我只能通過網(wǎng)絡(luò)>過程.php >預(yù)覽來查看結(jié)果。

我也嘗試在ajax上使用,但它只會導(dǎo)致頁面出現(xiàn)很多錯誤,因為缺少數(shù)據(jù)。

以下是索引.phpwindow.location.href = "your-url-to-redirect-to";


<body>

<input type='button' class="btn btn-success" id='but_screenshot' value='Take screenshot' onclick='screenshot();'><br/>

<script type="text/javascript">

    function screenshot() {

        var transform = $(".gm-style>div:first>div:first>div:last>div").css("transform");

        var comp = transform.split(",")

        var mapleft = parseFloat(comp[4])

        var maptop = parseFloat(comp[5])

        $(".gm-style>div:first>div:first>div:last>div").css({ 

            "transform":"none",

            "left":mapleft,

            "top":maptop,

        });

        html2canvas(document.getElementById('map'), {

            useCORS: true

        }).

        then(function(canvas) {

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

                $.ajax({

                    url: 'processing.php',

                    type: 'post',

                    data: {image: base64URL},

                    success: function(data){

                        console.log('Upload successfully');

                    }

                });

            }

        );

    }

</script>

</body>

這是processing.php


<?php

// upload screenshot

$image = $_POST['image'];

$location = "uploads/";

$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);

// end


uploadToApi($file);


function uploadToApi($target_file){

    require __DIR__ . '/vendor/autoload.php';

    $fileData = fopen($target_file, 'r');

    $client = new \GuzzleHttp\Client();

    try {

    $r = $client->request('POST', 'https://api.ocr.space/parse/image',[

        'headers' => ['apiKey' => '[API_KEY]'],

        'multipart' => [

            [

                'name' => 'file',

                'contents' => $fileData

            ]

        ]

    ], ['file' => $fileData]);

    $response =  json_decode($r->getBody(),true);

    if(empty($response['ErrorMessage'])) {

?>

<html>

    <head>

    <title>Result</title>

        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.0/css/bootstrap.min.css">

        <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js'></script>

        <script src='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.0/js/bootstrap.min.js'></script>

    </head>

    <body>

        <div class="form-group container">

            <label for="exampleTextarea">Result</label>

            <textarea class="form-control" id="exampleTextarea" rows="30">

            <?php

                foreach($response['ParsedResults'] as $pareValue) {

                    echo $pareValue['ParsedText'];

                }

            ?></textarea>

        </div>

    </body>

</html>

<?php

    } else {

        header('HTTP/1.0 400 Forbidden');

        echo $response['ErrorMessage'];

    }

    } catch(Exception $err) {

        header('HTTP/1.0 403 Forbidden');

        echo $err->getMessage();

    }

}

?>

查看完整回答
反對 回復(fù) 2022-09-12
  • 1 回答
  • 0 關(guān)注
  • 80 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號