I have a webapp where my users might want to get some data from me in xml format. The flow I was thinking of:
User clicks a button named "export"
I generate a long xml string using javascript.
Pop up a new window and just paste the xml string into it.
I would prefer saving the xml string into a text file for the user, but I don't think this is possible with javascript (security reasons).
Are there any other best practices for doing something like this? I guess this will work fine,
Thanks
You can add a hovering text field to the page and paste the XML into that. To make things more simple for the user, set the focus to the field and select everything (so they only have to press Ctrl+C).
If you can access server-side pages, you can generate the XML string using javascript, make an ajax call to give the server your string, then make the user download the generated file.
Related
I am doing a password manager web app (like LastPass etc), one of the things that has occurred to me is that after using PHP to retrieve the passwords from a db and decrypting them and then using JS to display them in the UI, the variables containing their passwords are visible if someone looks at the source code. Even if I did not use JS and used echo instead it would still be in the source code. Does anyone know of a, hopefully not too complex, way that can prevent the passwords from being in the source code?
If you're talking about the HTML source code, this is normal. But there is a few way to avoid it:
If you just want not to have it in your HTML when it is received by the user, then you can implement it via an Ajax request in javascript, to update the DOM with the text.
If you want that when the user do inspect on the page he doesn't see the password you can use an input and set in javascript the value of it. then you set the input as disabled so the user cannot modify it. You can even change the type as password when needed so it's displayed as ****** when you want to hide it.
Another way could be to add in javascript a css :after and tu put the value inside it. But it will still be visible somewhere I think.
You can use JavaScript to send an HTTP request (using xhr or fetch) to your backend, then you can manipulate the DOM to show the password.
I am working on adding a new feature to an existing Classic ASP application. In this feature the user will scan a bar-code which will input its value into a text field in a form within a bootstrap modal. The scanner is configured to send a TAB as well after the data.
What I need is a way to query the database on field exit and populate other fields in the modal with data from the query that is based on the scanned value. I need to do this without reloading the page or closing the modal so the user can verify this information and make changes before saving the form.
What is the best way to do this? I have no issue writing the SP, but do not have any idea how to call it and then return it's values. Can I possibly use JavaScript/PHP for this?
You will need to use some ajax
https://learn.jquery.com/ajax/
Basically you would send a request to your .asp script which will run the stored procedure then send a response using Response.Write.
Then parse that response in jquery.
Unlike ASP Classic, AJAX is a new technology so it works better with JSON.
There aren't many JSON libraries
You can use json2.asp:
https://github.com/nagaozen/asp-xtreme-evolution/blob/master/lib/axe/classes/Parsers/json2.asp
Or if you want you can try it XML, but its unpopular these days and more tedious to parse.
You mentionned PHP, that's not a bad idea because, it's all built in for you see:
http://php.net/manual/en/function.json-encode.php
Hope this helps
Im new at web developing.
I want something like:
A website, that everyone can enter. on the website u have 2 parts: one is filled with textbox so any user can write something in it and click button 'save comment'. He other side is filled with the execution of that button(it displays added text comment -but not just for a moment but that text is saved on that website). Simple as that...
Do i use java script?
Ive been looking for the answers but kinda didnt know how to ask gooogle bout that
scheme on that website:
----------------------/----------------
-textbox--------------/--constant text-
--add comment button--/--wrote by user-
----------------------/----------------
You have many possible ways to do that. One of the ways is to use html with jquery and send the result via web service (.asmx for instance) and save that result in a database (MSSQL for instance). So everytime you load the page you can get those saved results and display it on the relevant page. Another way is to use php with mysql or to use java...
If you don't want to use databases and server side code you can save the results in a cookie and then display those results in the page.
I am currently designing a Node.js web server that will store requests as JSON objects and store them in a text file.
An example of said text file is this:
{"elements":[
{"email":"test#test.com","timestamp":"22:10:54"},
{"email":"foo#foobar.com","timestamp:"09:56:49"}
]}
What I want to do is be able to append a given JSON into this text file. This would be more complicated than a simple fs.append() function, because I have to first get rid of the
\n]}
that closes the JSON, and then stick on
,{"email":"INPUT EMAIL HERE","timestamp":"INPUT TIMESTAMP HERE"}\n]}
to form the new completed JSON,
{"elements":[
{"email":"test#test.com","timestamp":"22:10:54"},
{"email":"foo#foobar.com","timestamp:"09:56:49"},
{"email":"INPUT EMAIL HERE","timestamp":"INPUT TIMESTAMP HERE"}
]}
I want to do all of this without having to load the text file with fs.readFileSync(path), because that would become more difficult with each new entry. So, my ultimate issue is that I need a way to strip off (effectively reverse-append) a few characters from the end of the file so that I can append on the newly inputted elements. I've already looked over the doc (http://nodejs.org/docs/latest/api/fs.html#fs_fs_createwritestream_path_options) and I saw no function for it, but I figured there has to be a way to do it.
I have created a JSP with various fields. I want to provide an option to export the page to a PDF before submit but after the user fills in the form.
How can this be achieved? I am struggling with this problem past many days and not able to get solution.
You might want to look into the FlyingSaucer project. It's a mechanism for producing PDF files from XML documents, and in particular from a fairly strict XHTML doctype. It really works quite well, and it supports some CSS3 features for doing things like page headings, intra-document bookmarks (like links), and is generally pretty well-behaved about CSS rules. I don't think it does forms, but you could probably fake that if it's going to end up as a non-interactive document anyway.
Link: http://code.google.com/p/flying-saucer//
(If it's not clear, this'd be a server-side solution. The form would have to be posted, and your server would build the PDF and ship it back to the client.)
Or just use AJAX to submit the form. The use clicks "Generate PDF" or whatever and an AJAX post is made to send the form data to the server and return a generated PDF. That submit can go somewhere else than the service/servlet which is processing the form data.
Just use the Print option in Firefox 3.5. It has an option to print to PDF file. Alternatively, you can use PDFCreator or some other virtual printer software that writes to PDF file instead of printing on paper.
I want to provide an option to export the page to a PDF before submit but after the user fills in the form.
This is not possible at the server side as the information isn't submitted to the server side yet. Your only resort is the browser capabilities and the knowledge of the user how to use them.
If you can live with changing the flow to submitting into some result page and providing an link to export the current result page to a PDF file, then combine this answer with iText.
If you are trying to output a report you can look at display table: http://displaytag.sourceforge.net/1.2/. It comes with a simple servlet filter that will allow you to click a simple link and export to pdf, excel , etc.