Cofey
Cofey

Reputation: 11404

How to decode JSONP data with jQuery?

I have some data that I'm retrieving using JSONP from a remote server. The content contains HTML and I need to make it so the characters render properly instead of printing the tags out. 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. Just about everything I've found in search results uses some type of server side code.

Upvotes: 0

Views: 610

Answers (1)

zzarbi
zzarbi

Reputation: 1852

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:

remoteScripts.js:

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

and so in your HTML page you can do via JQuery:

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

Upvotes: 1

Related Questions