0

I am using PhoneGap, in which we are allowed to use jQuery/JavaScript for manipulation operations. I make an Ajax request to a webservice I wrote in CakePHP, sending 3 things: id (from the address bar), and latitude and longitude (from HTML5 geolocation).

Now the problem is the same webservice gives correct data in the Firefox while in other browsers for the same lat and long it says "no data".

I used crossdomain in the Ajax request and I am using the POST method.

this is the request code

var request= $.ajax({
            type: "post",
            url: 'url',

            data:{ id: localStorage.getItem("id"), latitude: localStorage.latitude,longitude: localStorage.longitude},
            crossDomain: true,
            dataType: "xml",
            cache: false
       });
request.done(function (data){
//show data
});
request.fail(function (data){
alert('error');
});
4

2 回答 2

0

试试这个测试

if(navigator.geolocation) {
  // API is working
} else {
  // no support
}

它会告诉您您正在使用的浏览器是否接受地理定位 API。

于 2013-07-18T21:15:13.850 回答
0

好的,我得到了错误并通过谷歌搜索解决了它......问题是javascript在其他浏览器中的split函数,特别是在chrome中,整数被转换为字母我不知道为什么所以我使用这个函数来获得所需的值。 …………

function getUrlVars() {
                        var vars = {};
                        var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
                            vars[key] = value;
                        });
                        return vars;
                    }
                    var first = getUrlVars()["id"];

现在如果我提醒(第一);它会给我整数值,webservice 会将相关记录返回到该值

于 2013-07-19T11:19:39.120 回答