I am relatively new to ServiceNow, and I am building some UI pages where I basically do not need any of the SN structure except for Glide Ajax (I need to get data from a Script Include).
The problem is that when I select "Direct" the Glide Ajax functions are not available any more in the client script.
Does anybody know if this is possible to achieve? I searched everywhere without success.
Thanks a lot!
If you check "Direct", it omits all ServiceNow specific JavaScript and CSS. "GlideAjax" is ServiceNow specific JavaScript.
If the data that you are pulling back from the Script Include is static (meaning that you can pull it when the UI page is loaded) then you can probably do it inside an "evaluate" block in the HTML section of the UI page. You could have your Script Include return a JSON object as a string and store it in a variable. Then you could have your client JavaScript parse that variable. I am not a Jelly expert, so I would be curious to know if it works.
I'm working on a website that uses AJAX to retrieve data from the server and display it on the page. Django renders the initial page content using its template engine (so it will be indexed by search engines). When the user takes an action, jQuery fetches the new data via AJAX and the response is returned as JSON. I would like to have jQuery render this new content without violating the DRY Principle. Therefore I would like to use a templating engine that is "shared" between Django and jQuery. I've been running in circles trying to find the best solution but always seem to run into a road block.
Has this already been done? Here are the options I have thought of:
Use regular expressions to transform the Django template into correct jQuery template syntax, and render it in its raw form to the page. jQuery will then pick it up and use it to render the new data.
Extend the jQuery template engine to recognize the Django template syntax, again rendering the raw Django template to the page for jQuery to use.
Has this been successfully done before? Either way seems like a lot of work for anything but the simplest of Django templates because of the plethora of Django tags and filters that would need accounted for.
Your best bet is to pick a template language that has both Javascript and Python support, and use that everywhere.
As far as I know, Mustache is your best bet.
I haven't found a perfect solution since I asked this question, but for the sake of development time I resorted to sending back both JSON and HTML in the AJAX response. This way the django templates still perform the HTML generation, but javascript is still free to utilize the data without having to parse the HTML.
I am sending approximately twice the data over the network, but I'm going to live with it until my application grows to the point where a smaller response is beneficial. At that point I will probably look into something like Mustache as Rob mentioned.
We're currently doing a project that accepts user-provided html and has our own injected into it. This perfectly matches Play's abilities. However, I am at a loss as to how to use dynamic content as a view template without manual intervention. It seemed best to use a blob to store the information (given that there could be thousands of templates) and somehow load that way.
Any suggestions?
Thanks in advance.
If you really want to do this (I’m not convinced this is a good idea), have a look at the implementation of play.mvc.Controller.renderTemplate(String, Map<String,Object>) in the Play source, to see code that loads a template, binds variables and renders the template.
Is it possible to design an email using JSP to be sent through Spring 3.0's JavaMailSender mechanism? JavaMailSender probably has little to do with this question, but the idea is to take advantage of JSP's <fmt:message key="phrasetitle"/> internationalization mechanism, its variable/loop JSTL code and allow designers to easily hand me completed html emails.
Additionally, I could make a webpage that imports this JSP so that I can easily provide a link in each email to be able to view that email on the web in case their client doesn't see the html properly.
UPDATE: The 2 answers below suggest using Velocity for email instead of JSP, so it seems like that's the smart choice. However, just some quick scanning of stackoverflow suggests FreeMarker might be better suited for my needs. In particular I want to be able to have a JSP page which mirrors what's sent out in email. I'll have to translate the code from JSP to Velocity or FreeMarker, but the advantage FreeMarker gives me is I can reuse a lot of the JSP code, particularly taglibs. Does this make sense?
JSP is not a templating technology. For that for example Velocity is a better choice.
If you really insist in using JSP, then you have got to execute it locally by java.net.URL.
InputStream input = new URL("http://localhost:8080/context/mailtemplate.jsp").openStream();
There's some Spring documentation about using Velocity which will do what you want. I use it to handle emails in Spring and it works great.
What I typically do is to have an EmailService which which I call from a Controller whose job is to take care of sending emails. Methods within that accept a Command Object, which is accessed in the velocity template and rendered as a String (the email body). You can then use MailSender etc to send the mail.
Although I agree that Velocity or Freemarker may be a better choice, if you really need to render a JSP and capture the output as a String (which you could pass to a JavaMailer), check out my tutorial on Capturing JSP Output
It uses Spring 3, and also allows use of fmt:message, fmt:formatNumber, and spring:message. The idea is basically to use the RequestDispatcher.include method to render the page into a MockHttpServletRequest.
I'm not so familiar with Ajax but I keep hearing Json mentioned as some kind of competing option. Is there a rule for when to use one versus the other?
I'd like to process Javascript events in my app and update the front-end dynamically from the app but I'm not sure whether I need to use Ajax or Json for this.
Ajax and JSON are very different things.
From Ajax (programming):
Ajax, sometimes written as AJAX
(shorthand for asynchronous JavaScript
and XML), is a group of interrelated
web development techniques used on the
client-side to create interactive web
applications or rich Internet
applications. With Ajax, web
applications can retrieve data from
the server asynchronously in the
background without interfering with
the display and behavior of the
existing page. The use of Ajax has led
to an increase in interactive
animation on web pages and
better quality of Web services thanks
to the asynchronous mode. Data is
retrieved using the XMLHttpRequest
object. Despite the name, the use of
JavaScript and XML is not actually
required, nor do the requests need to
be asynchronous.
From Introducing JSON:
JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.
Here's some JSON:
{ "taco" : "awesome", "burrito": "less awesome", "fishTaco": "1000" }
Looks pretty much like an array in this case.
And you can use AJAX to get the JSON. I use it to return table data often. You've probably already used JSON-like data in your javascript but didn't realize it.
I prefer to request JSON data rather than XML or HTML. I find it easier to deal with than XML, and more flexible than HTML.
JSON is not a competing technology to AJAX it's just a data format.
Where you might hear competition is between XML and JSON, JSON having the advantage of being typically lighter and in native javascript already, XML having the advantage of portability and toolsets.
Introducing JSON
As some have stated, these are two different things entirely. AJAX is a method of using JavaScript to initiate HTTP requests to fetch data. That data can be in any sort of format, but most commonly XML, HTML, and yes, JSON.
So, as already mentioned, JSON is a data format much like XML or CSV, just with a different set of formatting rules.
Json is nothing more (and nothing less) than a format of the data you transfer with the Ajax-way of talking to the server.
Some transfer the data in the form of xml, other just plain text, others use Json.
More info about JSON on Wikipedia: http://en.wikipedia.org/wiki/Json
Ajax and JSON aren't the same thing. Ajax is a technique combining, among other things, lightweight asynchronous requests and typically some DOM manipulation, in order to create richer user interfaces in web applications.
The "X" in Ajax is often taken to mean "XML", and many sites using Ajax use XML as the format of the data returned by the server in response to such requests.
JSON (http://json.org) is a lightweight data interchange format based on Javascript's object notation. As such, it's easy to parse in Javascript. It's also a lot less verbose and repetitive than XML.
I think you may be talking about AJAX vs JSONP
http://en.wikipedia.org/wiki/Json#JSONP
If that's the case, the one benefit of using JSONP, is that you can get around the cross-site sandboxing (although, possibly introducing new security risks)
AJAX is used for get data from server, whereas JSON is just a data format which can used to send data to the server.
I thought I would provide this comparison from my class lecture
AJAX (Asynchronous JavaScript + XML) incorporates several technologies:
Standards-based presentation using XHTML and CSS;
Dynamic display and interaction using the Document Object Model (DOM);
Data interchange and manipulation using XML and XSLT;
Asynchronous data retrieval using XMLHttpRequest;
JavaScript binding everything together.
JSON, short for JavaScript Object Notation is a lightweight data interchange format. Its main application is in AJAX web application programming, where it serves as an alternative to the use of the XML format for data exchange between client and server.
The above answers are correct, but If you are new to using web technologies, all you need to know is simply
that Ajax is a subset of JavaScript.
It is a technology, a means for you to send only portion of the web page data back to the server to get processed
and get the response back while the user is interacting with other parts of the page. This way, the
Interaction with the page is consistent and seemless from the user stand point. Now, JSON on the other hand is
the how you can format the data (similar to XML) that you are sending back to the server, and getting back.
and it's used primarily with Ajax. It was developed and used mainly
because it is lightweight and human readable, which makes it more efficient and user friendly.
Hope that helps a bit.