简体   繁体   中英

Cross-browser issue while using jQuery Mobile

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');
});

Try this test

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

It will tell you if thebrowser you are using accept geolocation API.

ok i got the error and solved it by googling then...... the problem was javascript's split function in other browsers specially in chrome, integer was converted to alphabet i dont know why so i used this function to get the desired value........

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

and now if i alert(first); it will give me integer value, and webservice will return related records to the value

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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