Размещение объекта с использованием $ .ajax & jQuery - PullRequest
0 голосов
/ 01 апреля 2012

У меня есть приведенные ниже данные публикации JavaScript, когда они могут определить местоположение пользователя.

if (document.cookie.indexOf("latLng") == -1) {
    console.log("fired geolocation lookup");
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(success, error, {enableHighAccuracy:true,timeout:6000,maximumAge:2500});
    } else {
        //html5 geolocation isn't supported in this browser
        error('not supported');
        //render set location manually
    }
} else if (document.cookie.indexOf("latLng") == 0 ) {
    $(function() {
        organiseLocation();
    });

}

function success(position) {
    //cool we've got the location
    //var locationData = {"location": position.coords.latitude+", "+position.coords.longitude, "radius": 50, "type": "auto"};
    console.log("position ", position);
    $.ajax({
        type: "POST",
        url: "../set_location",
        data: position,
        dataType: "json",
        success: function(){
            console.log("success!");
        }
    });
}

function error(msg) {
    //we couldn't determine your location
    var s = document.querySelector('#status');
    s.innerHTML = typeof msg == 'string' ? msg : "failed";
    s.className = 'fail';
    //this needs cleaning up!
    console.log(arguments);
}

В Chrome все работает нормально, однако в Firefox и Safari я получаю следующую ошибку - любые идеи?

Illegal operation on WrappedNative prototype object
[Break On This Error]   

value = jQuery.isFunction( value ) ? value() : value;

1 Ответ

1 голос
/ 01 апреля 2012

Похоже, вам нужно использовать JSON.stringify() для сериализации вашего объекта:

$.ajax({
    type: "POST",
    url: "../set_location",
    data: JSON.stringify(locationData),
    dataType: "json",
    success: function(){
        console.log("success!");
    }
});

(отредактировано data: для строковых данных о местоположении)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...