1

I am using devexpress JS Charts which they accept data in a format of:

[{ category: 'Oceania', value: 35 },{ category: 'Europe', value: 728 }]

I am able to get the exact same format in my back end code by converting a DataTable to a Json. (I am getting the datatable after i run a couple of queries based of the user's selection)

Everything was working fine untill i decided to use an UpdatePanel to avoid the postbacks in the page every time the user was selecting an option (Please note that i am not experienced in something like this). Now ,though, i realized that i can't call a non static method with javascript in order to get the data. What i thought i could do is every time i have an ajax postback, i would run a method and insert into a hidden field the data and then grab it with javascript and populate my charts. When i am doing that it's not working as the data is stored as string... I tried a couple of things around it but i simple can't make this work...

I was grabbing the data before (with post back)

var data= <%=GetData()%>

The GetData() is a C# method that returns a string

private string GetJsonFormat(DataTable table)

In order to populate the charts i must use

$("#divID").dxPieChart({dataSource: data});

If i input the data into an input field and grab it like this

var data= $('#inputID').val();

It doesn't work because of the string quotes... I even tried to remove the quotes like this

data.substring(1,data.length()-1)

but didn't work either...

Can someone see an alternative way around this or a fix for this?

1
  • If the data is safe, have you tried using eval()? Commented Aug 15, 2013 at 7:33

1 Answer 1

1

The correct approach would be to use AJAX. For example, jQuery has built-in functions for getting JSON content from the server.

http://api.jquery.com/jQuery.getJSON/

It's extremely simple. The easiest approach is to get your button (or whatever triggers the event) to simply call:

$.getJSON('url/to/json/content', function(data) {
    // data is the returned JSON object so use it as you like
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.