开发者

write data in json format to js file?

开发者 https://www.devze.com 2023-01-10 22:35 出处:网络
I am thinking of this idea: 1. Request data from server and write to javascript file in json format using C#

I am thinking of this idea: 1. Request data from server and write to javascript file in json format using C# 2. When the page loads, the page loads the js file and I can use the data using javascript?

开发者_StackOverflow中文版

is this a good or bad idea? is there any example somewhere doing that?

thanks


I'd take into account:

  • Performance, do you expect the dataset to be small enough to be managed by browsers? How complex are the relationships between your entities?
  • Security, how will you secure the data to avoid malicious code execution?

Taking into account these concerns I'd recommend JSON for data interfaces.


JavaScript performance varies by browser, and can go downhill under load, but with that small of a dataset you shouldn't have to worry about that.

If you are using MVC, AJAX and JSON are very easy.


My company does this occasionally when the page is meant to hold only static data. It looks something like this in a .aspx document:

var initialData = <asp:Literal runat="server" id="MyAwesomeLiteral" Text="null" />;

myObject.init(initialData);

This only works if you're confident that your data can't be manipulated to bad ends. If you have IDs, especially sequential ones, encrypt them.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号