When I serialize my C# list to a JSON string, I can't get my javascript code to recognize it as a string.

in my Default.aspx.cs :

private string allDataJSON;
JavaScriptSerializer ser = new JavaScriptSerializer();
allDataJSON = ser.Serialize(new AccessAllData().getAllData());

in my javascript file:

var allDataJSON = <% =this.allDataJSON %>;
var myHeading = document.querySelector('h1');
myHeading.innerHTML = allDataJSON;

As it is, the first line in my javascript file gives me an error which says unexpected < symbol.... but I saw other answers here giving this syntax but they were 3-4 years old.

All I want here is for my h1 text to be the same as the one in the allDataJSON string.

Related posts

Recent Viewed