Prettify JSON in HTML from iframe? - html

Maybe my problem is simple because there are many similar requests, but I can't find the solution to my problem.
I build an HTML-website which makes a form request to a server. The server responses with a JSON text to this iframe on the website:
<iframe name="json_result" src=""></iframe>
The problem is, that this json string is on one line and with that not human-readable. How can I make it pretty? (with breaks and tabs, like firefox is doing it normally by its own in a new tab)
I know there are solutions like JSON.stringify() or google/code-prettify, but I don't know how to get the response json text from the iframe into these functions or maybe build some css classes around the iframe which formats the incoming json automatically?

It seems like you want to transform the content of the IFrame from the parent site. I don't think this is possible without reading it using AJAX instead of via an IFrame.

Related

Embed HTML content from another http request without an iframe

I want certain content on the website (data tables) to be available for including in other pages (like articles) on the same web site. I imagine the "Paste this code into article where you want the table: [..]" route.
I don't want an iframe, I want the html directly inserted (I already have the GET API that returns html table as one of the possible formats).
Is there a way how this is intended to be done in HTML?
I have looked around another questions but those seem to mainly struggle with CORS which is not an issue in my case.
My naive attepmt would be to make embed code like this:
<div
class="replace-me-by-src-content"
data-src="http://the.long.url" >
</div>
And the loading would be done by some ever-present javascript that would take care of each .replace-me-by-src-content element.
Is there a cleaner way without using javascript? You know - we can directly insert images or stylesheets by just providing the src attribute in certain tags and the browser takes care of doing the GET request and inserting the response. Can the same be done for plain html inserts?
You can use object to load the external page.
<object type="text/html" data="http://www.example.com" style="width:100%; height:100%"></object>
Or else you need to use jquery.
<script>$("#testLoad").load("http://www.example.com");</script>
<div id="testLoad"></div>
<object type="text/html" data="https://www.example.com" style="width:100%; height:100%"></object>

Jquery or json load data without refreshing page and add into html tags

I get some data on html/php page from database. And I edit it. But I want that data to change automatically without refreshing when I edit and click submit button. I have read that I must use json. But I can't add json values into html tags.
How can I do it ?
If you could not understand me, see this video.
You can use javascript to fetch the json file and manipulate the DOM accordingly. The example you provided uses jquery. Jquery provides a couple of ways to retrieve json data with ajax calls. This is all documented very well. See https://api.jquery.com/jquery.get/

Can you coerce <object> tag so it issues POST instead of GET?

I'm using an ASP classic app to create HTML <table>...<td> cells with SVG drawings encapsulated in an <object> tag, which works fine. Here is what the <object> looks like:
<object data="http://myserver.com/foo.asp?svgdata=data/bar.xml" type="image/svg+xml" border="1">Browser unsupported</object>
When the page loads, <object> issues a GET to the server (and ASP), with a parameter value in its data= parameter. My challenge is I'd like to create the svgdata= argument on the fly, and send a lengthy data payload in it to the server. So I'm hoping I could use POST to do so, since GET is size-restricted.
Is there a way to coerce the <object> to issue POST instead of GET? Assuming I could navigate the particularities of passing a correctly constructed svgdata= attribute.
Note, the final form of this is a pure HTML + SVG document in the browser DOM, it's not a Form or interactive otherwise.
Thank you, Stackoverflow readers!

How do I load data (csv file or similar) into a page via script tag?

Is there a way to load a resource in HTML5 via script tag? The following syntax does not seem to work.
<script src="file.structure" type="application/structure"></script>
thanks!
Ok looks like there is no way, but I think it would be an interesting addition, to be able to register particular parsers of specific mime-types...
solutions:
pure ajax
jsonp

How can I post data (form) to html page and hijacking the data in the middle?

the site addres: http://www.ynet.co.il/YediothPortal/Ext/TalkBack/CdaTalkBack/1,2497,L-3650194-0-68-544-0--,00.html
fill the form with rubbish.
Hit 'Send'
the form post the data to another HTML without any parsing of the data i've just added
How do they do it?
A likely option is that they are using a content management system where "html" on the URL doesn't actually mean it's a static html file.
This may be out of left field, but I've certainly used the occasional JS function to grab everything in the header and either parse it or pass it to another script using AJAX.
I'll sometimes use this method in a 404.html page to grab the headers of the previous page, parse them out to see where someone was trying to go and redirect them.
That is, as annakata said, one of the numerous options available.
Edit based on clarified question:
Numerous frameworks can be configured to intercept an html request - for instance asp.net can be set to handle any given extension and an HTTPModule could do anything with that. It's really up to web server configuration what it decides to do with any request.
also: you don't really want to be saying "hijack"