简体   繁体   English

如何使用jQuery解码JSONP数据?

[英]How to decode JSONP data with jQuery?

I have some data that I'm retrieving using JSONP from a remote server. 我有一些要从远程服务器使用JSONP检索的数据。 The content contains HTML and I need to make it so the characters render properly instead of printing the tags out. 内容包含HTML,我需要制作它以便字符正确呈现而不是将标签打印出来。 For example, if something has bold tags, it should just appear bold and not have the strong tags around it. 例如,如果某事物具有粗体标签,则它应该仅显示为粗体,而周围没有强标签。

This needs to be done in JavaScript/jQuery. 这需要在JavaScript / jQuery中完成。 Just about everything I've found in search results uses some type of server side code. 我在搜索结果中发现的所有内容几乎都使用某种类型的服务器端代码。

If you read http://en.wikipedia.org/wiki/JSONP you can understand that you need to wrap you content into a Javascript function such as: 如果您阅读http://en.wikipedia.org/wiki/JSONP ,则可以理解,您需要将内容包装到Javascript函数中,例如:

remoteScripts.js: remoteScripts.js:

function getContent(){
    return 'YOUR HTML CONTENT';
}

and so in your HTML page you can do via JQuery: 因此在HTML页面中,您可以通过JQuery进行操作:

$('YOUR ELEMENT').html(getContent());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM