HTML 在 Firefox 上不显示

发布于 2024-10-17 04:30:57 字数 2036 浏览 3 评论 0原文

我试图通过 AJAX 返回 PHP 页面,它总是在 Chrome 中加载。在 Firefox 中,它加载的时间大约为 5%,其他时间则加载任何内容,也没有 JS/PHP 错误。我只是直接回显 html 而不使用 CSS。

这是我的 Ajax:

if(geo_position_js.init()){
            geo_position_js.getCurrentPosition(displayPosition,error_callback,{enableHighAccuracy:true,options:5000});
        }
        else{
            alert("Functionality not available");
        }

        function error_callback(p)
        {
            alert('error='+p.message);
        }       

    function displayPosition(loc) {
        var mylat = loc.coords.latitude;
        var mylong = loc.coords.longitude;
        $.ajax({
            type: "POST",
            url: "distancetest.php",
            data: "long="+mylong+"&lat="+mylat,
            success: function(html2){
                $('#locationinfo').html(html2);
                console.log(html);
           }
        });

    }

我的 PHP 基本上执行了几次:

$query = "SELECT * FROM tbl_geo WHERE cat_id=1";
    $result = mysql_query ($query) or die(mysql_error());
    echo "<h2>Restaurants</h2>";
    while ($row = mysql_fetch_array($result)){
        if($row['lat'] != ''){
            $distance = distance($_POST['lat'], $_POST['long'], $row['lat'], $row['lng'], "k");
            if($distance < 2000){
                $attractions[] = array('name' => $row['name'], 'address' => $row['address'], 'distance' => $distance);
            }
        }
    }
    $attractions = array_sort($attractions,'distance');
    $attractions = array_values($attractions);
    for ($i = 0; $i <= 10; $i++) {
        if(isset($attractions[$i]['distance'])){
            echo 'You are '.$attractions[$i]['distance'].'km away from '.$attractions[$i]['name'].' at '.$attractions[$i]['address'].'<br/>';
        }
    }

在某些浏览器中工作,但在其他浏览器中不显示任何内容。有什么想法吗?

更新:事实证明这是 Firefox 中的地理定位问题。它无法获取位置,但不会返回到 error_callback 函数。实例如下: http://adamzwakk.com/geolocate/

I am trying to return a PHP page via AJAX and it always loads in Chrome. In Firefox, it loads about 5% of the time, the other times it loads with nothing with no JS/PHP errors. I'm just echoing straight html back without CSS.

Here is my Ajax:

if(geo_position_js.init()){
            geo_position_js.getCurrentPosition(displayPosition,error_callback,{enableHighAccuracy:true,options:5000});
        }
        else{
            alert("Functionality not available");
        }

        function error_callback(p)
        {
            alert('error='+p.message);
        }       

    function displayPosition(loc) {
        var mylat = loc.coords.latitude;
        var mylong = loc.coords.longitude;
        $.ajax({
            type: "POST",
            url: "distancetest.php",
            data: "long="+mylong+"&lat="+mylat,
            success: function(html2){
                $('#locationinfo').html(html2);
                console.log(html);
           }
        });

    }

My PHP is basically doing this a couple times:

$query = "SELECT * FROM tbl_geo WHERE cat_id=1";
    $result = mysql_query ($query) or die(mysql_error());
    echo "<h2>Restaurants</h2>";
    while ($row = mysql_fetch_array($result)){
        if($row['lat'] != ''){
            $distance = distance($_POST['lat'], $_POST['long'], $row['lat'], $row['lng'], "k");
            if($distance < 2000){
                $attractions[] = array('name' => $row['name'], 'address' => $row['address'], 'distance' => $distance);
            }
        }
    }
    $attractions = array_sort($attractions,'distance');
    $attractions = array_values($attractions);
    for ($i = 0; $i <= 10; $i++) {
        if(isset($attractions[$i]['distance'])){
            echo 'You are '.$attractions[$i]['distance'].'km away from '.$attractions[$i]['name'].' at '.$attractions[$i]['address'].'<br/>';
        }
    }

Works in some browsers, but displays nothing in others. Any ideas?

UPDATE: Turns out this is a problem with geolocation in Firefox. It fails at getting the position but doesn't come back to the error_callback function. Live example is here: http://adamzwakk.com/geolocate/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

剪不断理还乱 2024-10-24 04:30:57

您确定您的浏览器支持您正在做的事情吗?

试试这个:
http://html5demos.com/geo

您还可以下载wireshark,查看您发送的信息以及从服务器返回的信息。服务器。

将空白 php 页面(仅回显随机字符串)放在要生成 php 的同一目录中也是一个很好的做法,并查看它是否正常工作。在基于 Windows 的服务器上,一个常见问题是 PHP 可以设置为在特定目录中工作,而由于安装错误,PHP 在其他目录中可能会失败。
每个浏览器处理错误和警告消息的方式都不同,因此如果它在 Chrome 中工作,并不意味着它在其他所有浏览器上都工作。您尝试过 Safari 和 Opera 吗?

Are you sure that your browser supports what you are doing?

Try this:
http://html5demos.com/geo

You can also download wireshark and check the information sent by you and returned from the server.

It is also good practice to put blank php page (just echo a random string) in the same directory where you want to generate your php and see if it is working. On Windows based servers it is a common problem that PHP can be set to work in specific directories, and because of mis-installing can fail in others.
Every browser handles errors and warning messages differently, so if it works in chrome, it does not mean it works on everything else. Have you tried with Safari and Opera?

葬シ愛 2024-10-24 04:30:57

我打开了 FireBug,您点击了链接来查找我的地址。它返回了一堆显示“未定义”的链接。在 FireBug 中,它显示您的脚本正在返回以下内容:

<?xml version="1.0" encoding="utf-8" ?>
  <geoData>
    <restaurants>
    </place>
    </restaurants>
    <accommodations>
    </accommodations>
    <things>
    </things>
  </geoData>

我缩进了它以使其看起来更好。您的应用程序似乎没有在 XML 中返回任何内容。您还关闭了一个未打开的标签!

I opened up FireBug and your clicked on the link to find my address. It returned a load of links saying "undefined". In FireBug it shows that your script is returning this:

<?xml version="1.0" encoding="utf-8" ?>
  <geoData>
    <restaurants>
    </place>
    </restaurants>
    <accommodations>
    </accommodations>
    <things>
    </things>
  </geoData>

I indented it to make it look nicer. It appears your application is returning nothing in the XML. You are also closing a tag which isn't open!

清风无影 2024-10-24 04:30:57

谨慎使用 console.log()

当 Firebug 被禁用或未安装时,在 javascript 代码中使用 console.log() 会引发异常。 (95%的时间?)
我写了一个小包装函数“dump(var)” dump.js 检查 Firebug 是否已启用,因此在生产代码中使用它也是安全的。

附:
我注意到:

 success: function(html2){
   $('#locationinfo').html(html2);
   console.log(html);
 }

html 变量是之前定义的还是 html2

Use console.log() with caution

Using console.log() in your javascript code throws an exception when firebug is disabled or not installed. (95% of the time?)
I wrote a little wrapper function "dump(var)" dump.js that checks if firebug is enabled so it's also safe to use in production code.

PS:
I noticed:

 success: function(html2){
   $('#locationinfo').html(html2);
   console.log(html);
 }

Is the html variable defined earlier or did you mean html2.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文