在运行时加载JSON,而不是通过AJAX动态加载JSON [英] Load JSON at runtime rather than dynamically via AJAX

查看:82
本文介绍了在运行时加载JSON,而不是通过AJAX动态加载JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不认为这可以干净地完成,但是我仍然会问。

I don't think this can be done "cleanly", but I'll ask anyway.

我有一个需要通过JSON资源获取JSON资源的系统一个REST GET调用,以便初始化。系统等待直到onLoad事件,并触发ajax请求来检索资源,我认为这是最好的方式,因为资源需要运行时间。

I have a system which needs to get a JSON resource via a REST GET call in order to initialize. At the moment the system waits until the onLoad event and fires an ajax request to retrieve the resource, which I don't think is the best way to do it, as the resource is needed a run time.

我想要做的是以某种方式在HTML标签中的运行时加载资源,然后eval内容。但是我正在做的是一个被其他人使用的API,所以我想以逻辑和标准的方式实现这一点。

What I would love to do is somehow load the resource at runtime inside an HTML tag then eval the contents. But what I'm working on is an API to be used by others, so I would like to achieve this in a logical and standards based way.

那么有没有标签适合账单?可以放置在文档头中的标签,我可以在运行时读取和评估内容?

So is there any tag which fits the bill? A tag which can be placed in the doc head, that I will be able to read and eval the contents of at runtime?

请问,

Chris

推荐答案

我在想把它放在一个iframe中,但是我意识到你有内容类型是application / json的问题。当我测试了FF,IE和Chrome试图下载文件并询问用户在哪里存储(Opera显示文件)

I was thinking of putting it in an iframe but then I realized that you have a problem with that the content-type is application/json. When I tested FF, IE and Chrome was trying to download the file and asked the user where to store it (Opera displayed the file)

将其放在LINK中将不会帮助您,因为浏览器不会尝试获取文档(它只能获取已知资源,如样式表)

Putting it in a LINK will not help you since the browser will not try to fetch the document (it only fetches for known resources like style-sheet)

对我来说,您必须使用AJAX。你可以详细说明为什么这是一个问题吗?

To me it looks like you have to use AJAX. Can you elaborate on why that's a problem?

这篇关于在运行时加载JSON,而不是通过AJAX动态加载JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆