I have a MVC application that produces the following output in a browser when I visit a certain URL:
[{"name":"Victoria Day","date":"\/Date(1337583600000)\/"},{"name":"Canada Day","date":"\/Date(1341212400000)\/"},{"name":"Civic Holiday","date":"\/Date(1344236400000)\/"},{"name":"Labour Day","date":"\/Date(1346655600000)\/"},{"name":"Thanksgiving","date":"\/Date(1349679600000)\/"},{"name":"Remembrence Day","date":"\/Date(1352707200000)\/"},{"name":"Christmas","date":"\/Date(1356422400000)\/"},{"name":"Boxing Day","date":"\/Date(1356508800000)\/"}]
Of course, the source code has a bunch of html tags wrapped around that.
How can I assign this raw information to a Javascript array?
Considering your http request returns the raw data that you’ve posted, you should be able to use:
If that output that you want to parse resides in other place, you should load it via jQuery in var
textusing your custom selector. Note that varcleanedTextremoves the bad characters from date values, in order to parse them as valid javascript Date objects.Leave a comment if you have further questions. Good Luck!
JSFiddle working example: click here
Edit: You need jQuery.
Edit2: I think you need to use
$.getin order to retrieve your data from a custom url(make sure it’s from the same server or you might run into browser security issues). You should play a little with this and try check if your request goes to the correct path on the server(for example you can check on Google Chome browser under Developer Tools on Network tab all requests data). You should change the content offunction(data) {to match your needs.