I have this code in .vm file
<script...>
.....
var attr = attr0[i].id;
</script....>
#set($attr1 = $request.getParameter("attr"))
$attr1
How to get the jquery attribute (which is clientside) to velocity template variable which is serverside?
As I suggested in my comment you can use a parameter, something like this:
In your template get the entire current URL (URL + parameter)
Check for your parameter (es. attr)
If ther is the attr parameter and it has a value do something in your template
In your script create a variable with your current URL and append your parameter to it (es. var url = {$currentURL} + '?attr=attrValue')
Now you have just to call this URL.
Related
I want to pass url parameters in this format http://localhost:8000/api/projects/?id=2021&a=2&b=3&c=4 and get the values in view function
In DRF you can get values of perms like this...
URL = http://localhost:8000/api/projects/?id=2021&a=2&b=3&c=4
id = request.query_params.get('id')
a = request.query_params.get('a')
b = request.query_params.get('b')
c = request.query_params.get('c')
print(id,a,b,c)
Postman Screen
I want to generate the short id of number type, but when I call shortid method and output id and emaill, the contents of the output in the console are the same as the incoming variable. the gist in github
I get an answer that change 'var self = this ' to 'var self = {}', because 'this' in method equal 'global'.
I understood how we parse the url parameters in express routes, as in the example
How to get GET (query string) variables in Express.js on Node.js?
But where do the url parameters come from in the first place?
EDIT:
Apparently, I can build such a query with jquery (i.e $.get). I can append params to this query object. It s cool, but still i m trying to understand how we achieve this in the query that renders the page as a whole.
An example : when i choose the oldest tab below, how does SO add ?answertab=oldest to the url so it becomes :
https://stackoverflow.com/questions/30516497/how-do-we-add-url-parameters-ejs-node-express?answertab=oldest#tab-top
The string you're looking at is a serialization of the values of a form, or some other such method of inputing data. To get a sense of this, have a look at jQuery's built in .serialize() method.
You can construct that string manually as well, and that's pretty straight forward as well. The format is just ?var1=data1&var2=data2 etc. If you have a JSON object {"name": "Tim", "age": 22} then you could write a very simple function to serialize this object:
function serializeObject(obj) {
var str = "?";
for(var i = 0; i < Object.keys(obj).length; i++) {
key = Object.keys(obj)[i];
if (i === Object.keys(obj).length - 1)
str += encodeURIComponent(key) + "=" + encodeURIComponent(obj[key]);
else
str += encodeURIComponent(key) + "=" + encodeURIComponent(obj[key]) + "&";
}
return str;
}
Running seralizeObject({"name": "Tim", "age": 22}) will output '?name=Tim&age=22'. This could be used to generate a link or whatnot.
The page author writes them so. This is how they "come in the first place". The authors of an HTML page decide (or are told by website designers) where to take the user when he clicks on a particular anchor element on it. If they want users to GET a page with some query parameters (which their server handles), they simply add query string of their choice to the link's href attribute.
Take a look at the href attribute of the oldest tab you clicked:
<a
class="youarehere"
href="/questions/30516497/how-do-we-add-url-parameters-ejs-node-express?answertab=oldest#tab-top"
title="Answers in the order they were provided"
>
oldest
</a>
When you clicked it, the browser simply took you to path indicated in href attribute /questions/30516497/how-do-we-add-url-parameters-ejs-node-express?answertab=oldest#tab-top relative to the base URL http://stackoverflow.com. So the address bar changed.
stackoverflow.com may have its own system of generating dynamic HTML pages. Their administrators and page authors have configured their server to handle particular query parameters and have put in place their own methods to make sure that links on their pages point to the URL(including query string) they wish.
You need to provide URIs with query strings of your choice (you can build them using url.format and querystring.stringify) to your template system to render. Then make your express routes process them and generate pages depending on their value.
In my xpage which is bound to a domDoc datasource I want to build a preview mechanism for images stored in the datasource's richtext field. Designer and server are V 9.0.1.
The names of the attached images are stored as an array in a viewScope var and fed as source to a repeat control. The image control sits inside the repeat. I also put a link control alongside the image offering a means to download the file. The calculated url looks like this:
/dbpath/dbfile.nsf/xsp/.ibmmodres/domino/OpenAttachment/dbpath/dbfile.nsf/docunid/rtBodyField/filename.gif
Calculation of the link works perfect, but the images are never displayed. Instead Firebug tells me that the image's source url could not be resolved. And indeed I see that the db path part has been rendered twice before the /xsp/.ibmmodres/domino/OpenAttachment/ portion of the url (but only once after it!):
/dbpath/dbfile.nsf/dbpath/dbfile.nsf/xsp/.ibmmodres/domino/OpenAttachment/dbpath/dbfile.nsf/docunid/rtBodyField/filename.gif
Here's the code I'm using to calculate the source urls for both the link (using its value property) and the image (using its url property):
var unid=context.getUrlParameter('documentId');
var p=facesContext.getExternalContext().getRequestContextPath();
return p+'/xsp/.ibmmodres/domino/OpenAttachment'+p+'/'+unid + '/rtBodyFld/'+imgEntry;
Here's what I tried so far to solve that miracle:
a) calculate the db path (facesContext...) beforePageLoad, store it in a viewScope, then reference the viewScope when build the image's source ==> same result as above
b) used the image's value property instead of url ==> same result as above
c) use a standard html <img /> tag where the src argument is built using "#{javascript:...}" with the identical code as above ==> this works fine!
So I do have a workaround with solution c), but still I'd like to learn why the path element is doubled only in the first portion of the url, and only for image resources.
EDIT:
tried two more things:
d) pulled the image control outside my repeat then added a fixed (and valid) filename to the calculated url ==> same (bad) result as above
e) calculated the entire url portion only except the image file name beforePageLoad and stored that in a viewScope var ==> this is the weirdest result: outside the image viewscope contains the correct path info, but inside I see the same bad result as above. So it appears that inside the image the viewScope variable is altered in parts???
This is so weird that I feel I must have made a very simple and stupid error here, but what could that be?
Are you looking for how to calculate attachment URLs? Try this:
function getAttachmentURL(docID:java.lang.String, attachmentName:java.lang.String) {
var base = getBaseURL();
var middle = "/xsp/.ibmmodres/domino/OpenAttachment";
if (base.substr(0,4) == "/xsp") {
middle += base.substr(4);
} else {
middle += base;
}
var result = base + middle + "/" + docID + "/$File/" + attachmentName + "?Open";
return result;
}
function getBaseURL() {
var curURL = context.getUrl();
var curAdr = curURL.getAddress();
var rel = curURL.getSiteRelativeAddress(context);
var step1 = curAdr.substr(0,curAdr.indexOf(rel));
// Now cut off the http
var step2 = step1.substr(step1.indexOf("//")+2);
var result = step2.substr(step2.indexOf("/"));
return result;
}
Hope that helps!
Alright, it is as I feared: I had not taken into account that a relative url defined for an image control is automatically prefixed with /dbpath/dbfile.nsf/.
That's why that part always appeared twice no matter how I calculated my own url. It would have worked if I had used absolute urls (http://server/path/dbfile.nsf/...)
So instead the calculated url has to be built like that:
var unid=context.getUrlParameter('documentId');
var p=facesContext.getExternalContext().getRequestContextPath();
return '/xsp/.ibmmodres/domino/OpenAttachment' + p + '/' +
unid + '/rtBodyFld/' + imgEntry;
I have a webform.
I have written the php code in my module file which executes on webform submission.
In the code, I want to get the title of webform, and the name of the file attached to the webform.
Any idea about this?
Create a function in your .module file and write a select query in your function. Look at the code below.
function get_node_title($nid){
$node = db_fetch_object(db_query("SELECT title FROM {node} WHERE nid = %d", $nid));
return $node->title;
}