-1

I am using the Google maps Javascript API and when the user changes the directions/route on the map (draggable is set to true) I want to send the new route/directionsResult to my webservice backend. The issue I am facing is when I serialize DirectionsResults using JSON.stringify I don't seem to be getting the full list of objects correctly converted to strings.

   directionsDisplay.addListener('directions_changed', function () {
            sendToBackendService(directionsDisplay.getDirections());
        });

    function sendToBackendService(result) {
        var jsonToSend = JSON.stringify(result);

        $.ajax({
            type: 'POST',
            url: './api/DirectionsUserModified',
            data: jsonToSend,
            error: processCallbackError,
            success: function (apiJson) {
                alert("post of new directions success");
            }

        });

    }
gforg
  • 263
  • 1
  • 4
  • 19

1 Answers1

0

The issue will always be related to the local environment of execution of your JavaScript code. So , the version of web browser you are using.

Maybe the object can't be serialized properly because the size limit is reached. The navigator uses the local storage as buffer during json serialization process. If the limit is reached, the String is simply truncated or an error is thrown.

You could have a look to this other post, maybe it'll help

Community
  • 1
  • 1
Ludovic Frérot
  • 605
  • 4
  • 9