Generate pages with javascript - javascript

I'm working in a company where we are creating a web app, and we are moving all the legacy Yii PHP controllers to a more dynamic style.
Instead of generate HTML with PHP, the app it's moving to ask data to the java private API and receive JSON to generate HTML elements with Javascript, but there still are elements generated in the PHP code.
My question is: is it viable to use the server code (php, ruby, java...) just to generate some data in json and then create everything via javascript once it's received? (maybe everything but body, head tags :P)
Pros? cons?
If it's not a bad idea, is there any tips? Frameworks (like dust.js, backbone...) advices?
Why should I continue with this idea or why get away from it?
Edit:
Example:
A php generated page (from Yii framework using MVC as said - so not mixing backend and frontend) with the basic information like page header, side menu, footer, and some content without functionality. Once this page is received, the js takes control and adds extra functionality, right?
The other point is:
The same page but PHP not rendering anything but <html><body></body></html> (just the basic stuff, maybe something more like including js files, some headers... you know, the minimum needed) AND setting some javascript variables using JSON objects, with all the information needed by javascript to render the header, menu, body, etc.
So the pattern will be close to the one-page design by js (as backbone, angular.js, etc.).

Related

Converting HTML Template to pdf in JavaScript

I am currently using weasyprint to convert a HTML template to pdf. Now my company has decided to move from python to javascript for increased user experience or something.
Is there a PDF renderer in JavaScript that can do the following:
Use data on the client. I have data that under no circumstances can be transferred over the internet. (That is the reason I can not create the pdf on backend side or use external renderers.)
Use CSS page numbering
Use features like page headers and footers on print medium.
And of course can do the usual CSS layout.
Ideally there is something that can be used in python and javascript. But Weasyprint works great with python, so I can keep that if there is no "one tool to do the job everywhere".

how can i use Django with html CSS JS?

I am making a website and through some sources. I find out that Django is for backend and html CSS and JS is for front end.
So I am designing my pages in the later 3 and not started developing the backend.
Is there any way that I can use Django with html CSS and JS? (please suggest an easy method as I am a newbie ,however I am quite familiar with python )
Django would be used to match urls with pages. Specifically you would need to create a view that renders a template (here comes the html) and some static files (css, js). If you wont use a database i would suggest that you use flask which does the thing is described above much more easily.

Call methods in other HTML page

I am relatively new to web programming (just started html, javascript, php). I wanted to create a database manager for a website I am building. Now, in ios I would create a .h file called DBManager, with a list og methods I can call, and then import this file in any other .m file and do something like:
[DBManager uploadInage: image with completition...];
How can I do this for the web?
There is not a direct equivalent in the languages you mention.
HTML is a markup language and as such does not have funcitons at all.
Javascript and PHP are both interpreted languages, which can be used inline in your HTML. You will find that they aren't as structured in some ways as compiled languages like Objective-C. You can use different approaches to structuring your code, but there is no compiler enforcing them.
So for example, you can deploy some Javascript with your HTML which makes a method call, and it doesn't matter if that method was even written yet. As long as it can be found at runtime, it will work.
The same goes for PHP. Nothing will prevent you from writing and deploying your code making any method calls you like. As long as those methods can be found in some file that's included when the script runs, the code will work.
include() and require() are the commands used to pull in other .php scripts which contain the classes or functions you need. You could write a "header" script which includes all of your dependencies if you like to structure things that way. There are also dependency management tools like Composer - but these are entirely optional.
I don't think its safe (and even possible? Nah, I'm pretty sure it isn't possible ;) ) to directly communicate with a database from HTML / JavaScript / ... .
Objective - C is a language that has a good MVC pattern. (Model / View / Controller). HTML is a markup - language (VIEW - only). You can call a webservice from this view, (With the aid of AJAX or other..), and that webservice can communicate with a database, and provide you the needed information. ==> Anyhow, there is a need to create a webservice here!
You can also integrate everything in a Web-application. You can build a webapp on (I like Java, others like .NET, and there are many more...). This is an application that (just like Objective-C) uses an MVC pattern. The HTML page acts as the view, (Storyboard in XCode), you have a controller that builds and fills/returns the view to the user, (just as the ViewControllers).
You should look at both options, depending at what you want to do, both choices work.
I'm happy to help you with further questions or remarks.

Attach PDF to PDF as attachment (not as a page) via Javascript in HTML (not in Acrobat)

I would like to generate a PDF portfolio using JS from an HTML/CSS page on a local machine. I would use a PDF template file which includes a PDF portfolio Navigator in SWF form. I have successfully accomplished this using C# and a command line program, but can not identify the proper Javascipt components to do this browser-side or pseuo-server with Node.js. Basically, I am looking for something which will allow me to append a PDF to a new or existing PDF via configuration choices and an 'assemble' action using a JS or HTML button. iTextSharp provides the required PDF interaction functionality, but I can not figure out to run this inside an HTML to allow configuration via the HTML/CSS DOM (i.e. checkboxes, text field desciptors, etc...). Does a library with this type of functionality exist?
So you want to create a PDF using JavaScript?
On a quick google search, I found what appears to be a javascript library for creating and manipulating PDFs call jsPDF
If you want information on how to upload files with JavaScript alone, here is an article on how to do that. It also shows you how to use the file element.
For style, I recommend using a CSS Framework is you don't know much about CSS. I personally use Twitter Bootstrap for quickly prototyping things. It's quick and easy, and has good documentation. You can also use this to see how to make a form in HTML. I haven't got any good starter tutorials for HTML off the top of my list, sorry.
If you don't know much about JavaScript, when it comes to getting the options from the form, so that you can use them as configuration options, I'd suggest using the jQuery framework. It'll help you get up and running quickly enough
Note, all of this shouldn't replace basic training in JavaScript and HTML/CSS. Frameworks make things simpler, but if you don't know how to do something without a framework, you're going to have a hard time with a lot of the more complicated things. This goes for every language

JavaScript: Write to current HTML document using input from a separate HTML document?

Preface: Hi, all! Here goes. First and foremost, I am not familiar with jquery, so any jquery code posted will be irrelevant to me until i research it. I'm newly teaching myself JS. I have decent XHTML experience, decent CSS3 familiarity/understanding, and some (very little) application programming experience (C++, Java).
The Situation: I'm designing a website's home page whereon, with JavaScript enabled, links are overwritten and instead of loading a new HTML document/page for each main link, I alter sections of the home page using JS.
The challenge: I want to load new page content without loading an entirely separate page. A similar old HTML solution to such a challenge was to load page frames, right? I want to overwrite an entire container element using content from another separate HTML file on the server. (The external file could be tailored to fit into the main page, but it would be even better if I could pull a SECTION of an external HTML document, perhaps one element).
Can I do this using only JavaScript?
If not, what other scripting could be used in conjunction with JS?
Would I need to implement "AJAX"?
Must I use "HTML DOM"? - Edit: I see that DOM is just integral to the function of HTML etc.
Thank you all for your patience and your expert advice. I <3 StackExchange.
Yes you can do that using Javascript and jQuery, take a look at the load() method that's exactly what you need
http://api.jquery.com/load/
Yes it is using AJAX, but it's really easy to use don't worry.
Can I do this using only JavaScript?
No, because the server will need to serve you the content / data that you wish to place in the HTML page. You'll need to combine client-side scripting (JavaScript) with functionality on the web server (see your next question below).
If not, what other scripting could be used in conjunction with JS?
That would be your server-side language, such as PHP, Ruby, or Python.
Would I need to implement "AJAX"?
Yes, what you described is implemented using Ajax. You've mentioned the jQuery library and it indeed has functionality to perform an Ajax call to the server (see $.ajax). The basic idea is: your JavaScript code performs an Ajax call, your web server returns the HTML and then your JavaScript code receives it and places it in the HTML page.
Must I use "HTML DOM"?
Web pages always make use of "HTML DOM". You could read the article about Document Object Model on Wikipedia for more information: you have to use DOM but not by choice - it's part of how web pages work.

Categories

Resources