---
title: "Generic Handler Data to Ajax Json"  
description: "Generic Handler Data to Ajax Json"  
author: "Anonymous User"  
published: 2014-11-30  
updated: 2014-12-01  
canonical: https://www.mindstick.com/forum/12720/generic-handler-data-to-ajax-json  
category: "asp.net"  
tags: ["c#", "ajax", "json", "generics", "handler"]  
reading_time: 2 minutes  

---

# Generic Handler Data to Ajax Json

I have a [Handler](https://www.mindstick.com/forum/33532/handler-pagehandlerfactory-integrated-has-a-bad-module-managedpipelinehandler-in-its-module-list) which has some [data](https://www.mindstick.com/articles/13050/salesforce-aiming-to-dominate-predictive-analytics-with-data-science) inside as shown below:

{"city1": { "[name](https://yourviews.mindstick.com/view/87450/how-to-generate-a-brand-name-using-linkedin-comprehensive-guide)": "Adana","slug": "north-east", "[url](https://www.mindstick.com/forum/436/url-redirection)": "#", "[path](https://www.mindstick.com/articles/44333/4-expert-tips-on-how-to-pick-the-right-career-path)": "M 156.53125,407.40625 L 156.71875,408.5625 L 157.1875,407.8125 L 156.53125,407.40625 z"}}

P.S: The path is coming from [SVG](https://www.mindstick.com/forum/159187/create-svg-progress-bar-to-move-anti-clockwise-using-css) image. it draws a city border and there are many cities.

I try to get the data from this handler to [variable](https://www.mindstick.com/articles/1807/objective-c-data-types-variables-object-creation) to use it later...

**[CODE](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii):**

```
  <script type="text/javascript">     var paths;         $.ajax({            url: '/paths.ashx',            dataType: 'json',            contentType: 'application/json',            responseType: "json",            success: function (data) {                paths = data;                alert(paths);            },            error: function (data, status, jqXHR) {                alert(status);            }         });  jQuery(function ($) {         var c = Raphael('map', "100%", "100%");        c.safari();        var label = c.popup(0, 0, "").hide();        attr = { fill: '#898989', stroke: '#FFFFFF', 'stroke-width': 2, 'stroke-linejoin': 'round' }        arr = new Array();        for (var item in paths) {            var p = c.path(paths[item].path);            arr[p.id] = item;            p.attr(attr);            p.hover(function () {                this.animate({                    fill: '#8fbf27'                }, 200);                bbox = this.getBBox();                label.attr({ text: paths[arr[this.id]].name }).update(bbox.x, bbox.y + bbox.height / 2, bbox.width).toFront().show();            }, function () {                this.animate({                    fill: attr.fill                }, 200);                label.hide();            })            .click(function () {                location.href = paths[arr[this.id]].url;            })        }    });  </script>
```

The [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) comes [right](https://www.mindstick.com/articles/12766/check-whether-you-are-doing-digital-transformation-right-or-not) here...paths or data is undefined, it's always empty. But paths.ashx is not empty at all...

I couldnt find the solution...could you take a look pls...

## Replies

### Reply by Anonymous User

Put your jQuery .ajax() function inside of the jQuery DOM ready function and the drawing logic inside the success handler of the AJAX call, like this:

```
<script type="text/javascript">    var paths;     jQuery(function
($) {        $.ajax({            url:'/paths.ashx',            dataType:'json',           
contentType: 'application/json',           
responseType: "json",            success:function (data) {                paths= data;                alert(paths);                var c= Raphael('map', "100%", "100%");               
c.safari();                var label = c.popup(0, 0, "").hide();                attr ={ fill: '#898989', stroke: '#FFFFFF', 'stroke-width': 2, 'stroke-linejoin':
'round' }                arr =new Array();                for(var item in paths) {                   
var p = c.path(paths[item].path);                   
arr[p.id] = item;                   
p.attr(attr);                   
p.hover(function () {                   
this.animate({                       
fill: '#8fbf27'                    },
200);                   
bbox = this.getBBox();                   
label.attr({ text: paths[arr[this.id]].name }).update(bbox.x, bbox.y +
bbox.height / 2, bbox.width).toFront().show();        }, function ()
{           
this.animate({                fill:attr.fill            }, 200);           
label.hide();        })       
.click(function () {           
location.href = paths[arr[this.id]].url;        })    }        },        error:function (data, status, jqXHR) {           
alert(status);        }    });});
```


---

Original Source: https://www.mindstick.com/forum/12720/generic-handler-data-to-ajax-json

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
