post 405(不允许使用方法)发送@jquery.min.js:2 ajax@jquery.min.js:2 coords2country@main.js:77 showposition@main.js:100

8yparm6h  于 2021-09-13  发布在  Java
关注(0)|答案(0)|浏览(196)

当扩展时,它指向coords2country(),当它在实时服务器上运行时,会出现as 405方法not allowed多次更改url,并测试了js代码,但我不明白为什么它总是出现uip错误
jquery.min.js:2篇文章http:///libs/php/getcountry.php 405(方法不允许)
这件事有点棘手,谢谢你的帮助

var coordinates = [];

    function coords2country() {
        $.ajax({
            type: 'POST',
            url: 'libs/php/getCountry.php',
            data: {
                lng: coordinates[1],
                lat: coordinates[0]
            },
            dataType: 'json',
            success: function (result) {

                console.log(result);

                $("#search").val(result.openCage.results[0].components["ISO_3166-1_alpha-2"]).trigger('change');
            }
        })
    }

    function showPosition(position) {
        let lat = position.coords.latitude;
        let lng = position.coords.longitude;
        coordinates.push(lat);
        coordinates.push(lng);
        coords2country();
    }
<?php

        $executionStartTime = microtime(true) / 1000;      

            $url = 'https://api.opencagedata.com/geocode/v1/json?q='.$_REQUEST['lat'].'+'.$_REQUEST['lng'].'&key=ded71ef2f8844e8eb8d8fb9970863854';

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

            curl_setopt($ch, CURLOPT_URL, $url);
            $openCage = curl_exec($ch);

            curl_close($ch);

            $openCage = json_decode($openCage, true);

                // Final Output
        $output['status']['code'] = "200";
        $output['status']['name'] = "OK";

        $output['openCage'] = $openCage;

        $output['status']['returnedIn'] = (microtime(true) - $executionStartTime) / 1000000 . " ms";

        header('Content-Type: application/json; charset=UTF-8');

        echo json_encode($output);

    ?>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题