未定义从php代码函数调用javascript函数


calling javascript function from php code function is not defined

我有以下代码段,它从php代码中调用showKML javascript函数。但是,它给了我以下错误:未捕获引用错误:showKML未定义

<?php
    $upload = $_SERVER['PHP_SELF'];
    if(isset($_POST['kmltest'])) {
        $target_path = "uploads/";
        $fn =  basename( $_FILES['uploadedfile']['name']);
        $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
        //echo $target_path ;
        if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
            echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
            echo "<script type='"text/javascript'"> showKML(); </script>";  
        }else
            echo "There was an error uploading the file, please try again!";
    }
?>
<script  type="text/javascript">
    function initialize() {
        if (GBrowserIsCompatible()) {
            map = new GMap2(document.getElementById("map"));
            map.setCenter(new GLatLng(25.22903, 55.46612), 13);
            map.addControl(new GSmallMapControl());
            map.addControl(new GMapTypeControl());
            map.clearOverlays();
            document.getElementById("lat").value = "25.22903";
            document.getElementById("lng").value = "55.46612";
        }
    }
    function showKML() {
    //alert(filename);
        initialize();
        document.getElementById('lat').disabled = true;
        document.getElementById('lng').disabled = true;
        var exml;
        exml = new EGeoXml("exml", map, ("uploads/test.kml"));
        exml.parse();
        exml.show(); 
    }
    function startShape() {
        ...
    }
    function startDrawing(poly, name, onUpdate) {
           ... 
    }
    function showcoor (poly) {
        ...
    }
    function drawpoint() {
        ...
    }
    </script>

非常感谢您的帮助

Javascript按照文件中的顺序执行/解释。当您的PHP代码输出<script>showKML()</script>代码块时,还没有遇到实际的function showKML(..) {...}定义,因此会出现此错误。

在运行PHP之前,移动要输出的函数定义。