My current project has a .js file with hard coded data in it. So I am referencing this file and on clientside. I am using this file to get the data when ever I require on client side. But my task is to generate this .js file dynamically. I am getting my values in json format from database. SO I need a way to write this json formatted data into .js file, so I can use that written data on client side.
Needed Format in JS:
var list = new Array();
list["1000"] = "TestEvent1";
Actual Json Format:
{
"__metadata": {
"type": "event_Result"
}, "event_id": 1000, "event_GROUPId": 17, "event_name": "TestEvent1",
}
Please help me.
Thanks
You can have a generic handler
ashxthat outputs javascript content. Set your output content type to “text-javascript”.It doesn’t have to have a file extension of
.js, the content type and how it’s reference is what matters<script type="text/javascript" src="myJavascript.ashx"></script>