camerican / Help-Desk

Help Desk for NYCDA Projects
1 stars 1 forks source link

Short Question #8

Closed jamessullivan77 closed 7 years ago

jamessullivan77 commented 7 years ago

can I add this as another function underneath the last one we created using success?

 success: function(){ 
      google.maps.event.addListener(map, "rightclick", function(event){
      event.latLng.lat();
      event.latLng.lng()
        })
camerican commented 7 years ago

You could add the success key value pair within your jQuery.ajax callback function.

jamessullivan77 commented 7 years ago

like this?

$('#add_marker').fadeIn().click(function(event){
    console.log('clicked, friend');
    $.ajax({
        url: '/map',
        method: 'POST',
        data: { 
          x: location.coords.lat,
          y: location.coords.long
        },
        success: function(data){
          marker.setIcon({
            url: '/assets/homeless.png',
            scaledSize: new google.maps.Size(50, 50)
          });
        },
      success: function(event){ 
        marker.setIcon({
          url: '/assets/homeless.png',
          scaledSize: new google.maps.Size(50, 50),
         ("rightclick", function(event){
          event.latLng.lat();
          event.latLng.lng()
        })
      }
    });
  });
camerican commented 7 years ago

You're only allowed to apply a single key per object, so the second success function is now overriding the first. I would simply handle everything you need inside the existing success callback.

jamessullivan77 commented 7 years ago

ok great, ill combine the two and get back to you if there is an error, thanks!