简体   繁体   English

如何使用Prototype.js发布到PHP脚本

[英]How to post to a PHP script using Prototype.js

I'm brand new to prototype.js and trying to do a simple GET request to a PHP script. 我是prototype.js的新手,并尝试对PHP脚本执行简单的GET请求。 The Javascript show do the following: Javascript show执行以下操作:

  1. Get the users latitude and longitude 获取用户的经度和纬度
  2. Pass the lat/long to the doStuff() function 将经/纬度传递给doStuff()函数
  3. Pass the lat/long to my PHP script (savecoords.php) to be saved. 将经/纬度传递到我的PHP脚本(savecoords.php)中进行保存。

For some reason, it's like this code isn't even executing even though I am sure I'm using an HTML5 capable browser that implements the Geolocation API. 出于某种原因,即使我确定我使用的是支持Geo5 API的HTML5浏览器,该代码甚至都没有执行。 Here is the code: 这是代码:

if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {
        doStuff(position.coords.latitude, position.coords.longitude);
    });
}

function doStuff(mylat, mylong) {
    new Ajax.Request('savecoords.php', {
        method: 'get',
        parameters: {
            'latitude': myLat,
            'long': myLong
        }
    }
}

Any ideas? 有任何想法吗?

In order to figure out why your function is not being called, you'll likely need to pass in an error callback . 为了弄清楚为什么不调用您的函数,您可能需要传递错误回调 For example: 例如:

if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(yourFunction, function (error) {
        console.log(error.message, error.code);
    });
}

This will provide you with the error code and message to narrow down why your function isn't being called. 这将为您提供错误代码和消息,以缩小未调用函数的原因。 The code will return one of several values, and the message should provide greater detail. code将返回几个值之一,并且message应提供更多详细信息。 From the MDC page linked above: 在上面链接的MDC页面上:

UNKNOWN_ERROR (numeric value 0) UNKNOWN_ERROR(数值0)

The location acquisition process failed due to an error not covered by the definition of any other error code in this interface. 由于该接口中任何其他错误代码的定义未涵盖的错误,导致位置获取过程失败。

PERMISSION_DENIED (numeric value 1) PERMISSION_DENIED(数值1)

The location acquisition process failed because the application origin does not have permission to use the Geolocation API. 位置获取过程失败,因为应用程序源没有使用Geolocation API的权限。

POSITION_UNAVAILABLE (numeric value 2) POSITION_UNAVAILABLE(数值2)

The position of the device could not be determined. 无法确定设备的位置。 One or more of the location providers used in the location acquisition process reported an internal error that caused the process to fail entirely. 位置获取过程中使用的一个或多个位置提供程序报告了一个内部错误,导致该过程完全失败。

TIMEOUT (numeric value 3) 超时(数值3)

The specified maximum length of time has elapsed before the implementation could successfully acquire a new Position object. 在实现可以成功获取新的Position对象之前,经过了指定的最大时间长度。

I'm sure that this doesn't solve your problem entirely, but it should give you the necessary insight to make some progress. 我敢肯定这不能完全解决您的问题,但是它应该为您提供必要的见识以取得一定的进展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM