serverside-javascript

How do I call an SSJS method with parameters from javascript

老子叫甜甜 提交于 2019-11-29 18:36:56
I have a url containing a hash e.g http://www.acme.com/home.xsp#key=1234 When the url above loads in the browser I need to call a serverside javascript based on the value in the hash. I have found a few ways of retriving the hash client side like this var key = getHashUrlVars()["key"]; so I have the key available in my client side script in the onclientload event. So in the same onClientLoad event I now need to call my server side javascript method so I have tried the following '#{javascript:doStuff(key)}' '#{javascript:doStuff(' + key + ')}' ..and a few other ways. but I can't get it to work.

Libraries to write xml with JavaScript

血红的双手。 提交于 2019-11-29 02:59:03
问题 I am doing some server side coding with JavaScript (node.js) and I would like to write valid xml. I found two libs, but I am sure there are more/better!? http://goessner.net/download/prj/jsonxml/ (LGPL) not yet released: https://sourceforge.net/projects/jsonix (LGPL) Requirements: open source (for commercial usage) Would be cool if the project is fast, small and simple to use (in that order). And I would like to have a bit lower level access ala doc.addElement('xy').addAttr('name', 'bob');

How to convert character encoding from CP932 to UTF-8 in nodejs javascript, using the nodejs-iconv module (or other solution)

和自甴很熟 提交于 2019-11-29 00:15:35
I'm attempting to convert a string from CP932 (aka Windows-31J) to utf8 in javascript. Basically I'm crawling a site that ignores the utf-8 request in the request header and returns cp932 encoded text (even though the html metatag indicates that the page is shift_jis). Anyway, I have the entire page stored in a string variable called "html". From there I'm attempting to convert it to utf8 using this code: var Iconv = require('iconv').Iconv; var conv = new Iconv('CP932', 'UTF-8//TRANSLIT//IGNORE'); var myBuffer = new Buffer(html.length * 3); myBuffer.write(html, 0, 'utf8') var utf8html = (conv

JavaScript pass scope to another function

夙愿已清 提交于 2019-11-28 18:44:36
问题 Is it possible to somehow pass the scope of a function to another? For example, function a(){ var x = 5; var obj = {..}; b(<my-scope>); } function b(){ //access x or obj.... } I would rather access the variables directly, i.e., not using anything like this.a or this.obj , but just use x or obj directly. 回答1: The only way to truly get access to function a 's private scope is to declare b inside of a so it forms a closure that allows implicit access to a 's variables. Here are some options for

Are there any static Call-Graph and/or Control-Flow-Graph API for JavaScript? [closed]

一个人想着一个人 提交于 2019-11-28 15:51:37
问题 Are there any Call-Graph and/or Control-Flow-Graph generators for JavaScript? Call Graph - http://en.wikipedia.org/wiki/Call_graph Control Flow Graph - http://en.wikipedia.org/wiki/Control_flow_graph EDIT: I am looking specifically for a static tool that let me access the graph using some API/code 回答1: To do this, you need: parsing, name resolution (handling scoping) type analysis (while JavaScript is arguably "dynamically typed", there are all kinds of typed constants including function

Preventing XSS in Node.js / server side javascript

末鹿安然 提交于 2019-11-28 15:38:16
Any idea how one would go about preventing XSS attacks on a node.js app? Any libs out there that handle removing javascript in hrefs, onclick attributes,etc. from POSTed data? I don't want to have to write a regex for all that :) Any suggestions? One of the answers to Sanitize/Rewrite HTML on the Client Side suggests borrowing the whitelist-based HTML sanitizer in JS from Google Caja which, as far as I can tell from a quick scroll-through, implements an HTML SAX parser without relying on the browser's DOM. Update: Also, keep in mind that the Caja sanitizer has apparently been given a full,

Why does the JavaScript need to start with “;”?

允我心安 提交于 2019-11-28 15:09:13
I have recently noticed that a lot of JavaScript files on the Web start with a ; immediately following the comment section. For example, this jQuery plugin's code starts with: /** * jQuery.ScrollTo * Copyright (c) 2007-2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com * Dual licensed under MIT and GPL. * Date: 9/11/2008 .... skipping several lines for brevity... * * @desc Scroll on both axes, to different values * @example $('div').scrollTo( { top: 300, left:'+=200' }, { axis:'xy', offset:-20 } ); */ ;(function( $ ){ Why does the file need to start with a ; ? I see

How do I call an SSJS method with parameters from javascript

こ雲淡風輕ζ 提交于 2019-11-28 12:35:10
问题 I have a url containing a hash e.g http://www.acme.com/home.xsp#key=1234 When the url above loads in the browser I need to call a serverside javascript based on the value in the hash. I have found a few ways of retriving the hash client side like this var key = getHashUrlVars()["key"]; so I have the key available in my client side script in the onclientload event. So in the same onClientLoad event I now need to call my server side javascript method so I have tried the following '#{javascript

Is there a way to test circular reference in JavaScript?

两盒软妹~` 提交于 2019-11-28 07:41:54
I'm making a game, and I've come across a problem... When I try to save, JSON fails and reports that circular reference is being made somewhere. I don't think it actually is, I can't see it, so is there an algorithm or anything which could tell me where it is exactly (between which objects and stuff)? Also, is there a JSON alternative that can save circular reference? I'm running a node.js server, I saw this , but I can't get it to work (it's not made as a module i can require() in my code). If you want to serialize a circular reference so you can save it, you need to make the reference

What is the correct way to chain async calls in javascript?

北战南征 提交于 2019-11-28 05:59:27
I'm trying to find the best way to create async calls when each call depends on the prior call to have completed. At the moment I'm chaining the methods by recursively calling a defined process function as illustrated below. This is what I'm currently doing. var syncProduct = (function() { var done, log; var IN_CAT = 1, IN_TITLES = 2, IN_BINS = 3; var state = IN_CAT; var processNext = function(data) { switch(state) { case IN_CAT: SVC.sendJsonRequest(url("/api/lineplan/categories"), processNext); state = IN_TITLES; break; case IN_TITLES: log((data ? data.length : "No") + " categories retrieved!