Pass object through jquery trigger

I'm trying to make something pretty simple, but I get a weird result. I have an event trigger that I use to pass the json object, but when it goes to the other side, this is a function ... I warn the result and it shows this:

warning example:

alert('value of lattitude? ' + map.currentLatLng.lat); 

result:

lattice value? function () {return this [a];}

I tried to configure a trigger with or without a literal shell:

 $('body').trigger('updateLocation', [{lat:38.905003, lng:-77.066497}]); $('body').trigger('updateLocation', {lat:38.905003, lng:-77.066497}); 

What am I doing wrong?

+2
source share
1 answer

Try the following:

 $('body').bind('updateLocation',function(event,obj){ alert(obj.lng); }); $('body').trigger('updateLocation', [{lat:38.905003,lng:-77.066497}]); 

+10
source

Source: https://habr.com/ru/post/1344044/


All Articles