Send Geometry JSON to aspx Handler using JQuery Ajax Submit

652
1
03-18-2012 10:30 PM
SureshRajamani
New Contributor II
I am trying to send Javascript api Geometry JSON to Asp.net Handler using Jquery Ajax Submit.But i am getting javascript error while posting GEOMETRY JSON.
Here is my code i am trying.

    var jsondata = dojo.toJson(geometry.toJson());
       
        $('#ajax-button').click(function () {
            $('#frmUpload').ajaxSubmit({
                data: jsondata,
                contentType: "application/json; charset=utf-8",
                dataType: 'json',
                success: function (r) {
                    $('#ajax-results').html(r);
                    $('input:file').MultiFile('reset');
                }
            });
        });


If i pass the geometry like below it works fine.
 
    var jsondata = dojo.toJson(geometry.toJson());
       
        $('#ajax-button').click(function () {
            $('#frmUpload').ajaxSubmit({
                data: ' {"x":-10753913.140888039,"y":4632637.5074609965,"spatialReference":{"wkid":102100}}',
                contentType: "application/json; charset=utf-8",
                dataType: 'json',
                success: function (r) {
                    $('#ajax-results').html(r);
                    $('input:file').MultiFile('reset');
                }
            });
        });


Please help me how to send the Geometry JSON to server like this
dojo.toJson(geometry.toJson())
0 Kudos
1 Reply
andrewj_ca
Occasional Contributor II
Maybe this will help, in the first code example you are passing a json object where as in the second example you are passing text.  And yes, they are different.  Try passing the json as string and then use the "JavaScriptSerializer()" to serialize it in asp.
0 Kudos