0

I am using jquery Ajax following line of code having problem only with Firefox and Blackbarry browsers

postion:

navigator.geolocation.getCurrentPosition(currentPosition);

function currentPosition(res){
                window.res = res;
}

Code:

var postion = window.res;

    $.ajax({
          url: 'SendLocation',
          type: 'post', 
          data: position, // Position is navigator.geolocation.getCurrentPosition
          success: function(res){
                alert(res);
       }
    });

Error:

NS_ERROR_XPC_BAD_OP_ON_WN_PROTO: Illegal operation on WrappedNative prototype object

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

After reading FormData Object not submitting via jQuery AJAX call post I added following line of code and code become processData: false, contentType: false,

Updated code:

$.ajax({
      url: 'SendLocation',
      type: 'post', 
      data: position, // Position is navigator.geolocation.getCurrentPosition
      processData: false,   //Added this line
      contentType: false,   //Added this line

      success: function(res){
            alert(res);
   }
});

with this no error was oucurring but code also stops working.

9
  • do you mean, position = navigator.geolocation.getCurrentPosition? because that would be invalid. position = navigator.geolocation.getCurrentPosition(...) would also be invalid. Commented May 12, 2013 at 15:56
  • 1
    And you know how to geolocate, and that it's async ? Commented May 12, 2013 at 15:58
  • @adeneo I am using gerolocation async. Commented May 12, 2013 at 16:04
  • @KevinB I have updated the question for your understanding but this is just an example. Commented May 12, 2013 at 16:12
  • 1
    What's happening is jQuery is trying to convert the object to a string. You need to instead convert said object to the string that your server-side system is expecting so that jQuery won't attempt to do it for you. you can't send a javascript object as-is over ajax, it has to be converted to a string format. jQuery can handle that conversion for you with simple objects, but with more complex objects, it can't. Commented May 12, 2013 at 16:44

2 Answers 2

0

I suggest using serialize() on your position variable as it would be trying to send the geolocation DOM object..

https://developer.mozilla.org/en-US/docs/DOM/window.navigator.geolocation.getCurrentPosition

This error would show up if you were using firebug and inspecting your POST vars.

Sign up to request clarification or add additional context in comments.

4 Comments

No can't use serailize becuase I need object on NodeJS server as it is.
@ArhamAliQureshi You can't send arbitrary javascript objects to the server. Maybe you should be more specific about what you're trying to do.
@AaronDufour. I am using NodeJS server, it is a javaScript server understand javaScript Objects. Working fine in Chrome and IE10
@ArhamAliQureshi Repeating yourself really isn't going to get you anywhere. What are you actually doing with the object? My guess is that the browsers it's working in serialize that object in its toString method.
0

Thanks all guess for helping me out but here let me tell you what I did. I just just select my required values from the position object and create a new object and filled it with my data that I got from position and POST it to the server and now its working fine Thanks..!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.