How to set target folder in JavaScript - javascript

How can I set the root folder in JavaScript when using Ajax?
This is my code?
var url="../../ajax_permission_data.php"
url=url+"?opp="+operation+"&userid="+userId;
url=url+"&sid="+Math.random()
But I am getting error file not found. If I am putting this file in same folder then it will work. But I don't want to all the files in same folder. So please help me how to set the path.

var path="http://www.mysite.com/";
var url=path+"folder/ajax_permission_data.php";
url=url+"?opp="+operation+"&userid="+userId;
url=url+"&sid="+Math.random();

Related

How to locate the right path for a .js file when using require

I have an ExpressJS project where I want to use .js module inside another. I use require to get the .js module but it can't find the module because the path is not correct. How can I see or find what is the correct path for a local module.
Here is my project hierarchy/structure
This is what I have tried inside programController.js - another thing is I don't quite understand using "." in path string.
var Program = require('.././program.js');
var FinishProgram = require('.././finishProgram');
The . and .. notation in paths represent a path relative to the file they're being required from.
Meaning of . and .. Wildcards
. - inside the same directory this file is in (also referred to as the current working directory)
.. - inside the parent directory of the current directory
When you use multiples of these together it creates a relative path pattern. So for programController.js to access program.js your path should be
var Program = require('../../models/program');
This path means, go up 2 folders to the App directory and locate the models folder, then load the file program.js.
Following the same rules, you can also access finishProgram.js
var FinishProgram = require('../../models/finishProgram');
. represents the current directory and is redundant in your case.
The paths are simple relative paths that are used to determine how to navigate to the required files.
This should work for you:
var Program = require('../../models/program');
var FinishProgram = require('../../models/finishProgram');
Note that the extension .js is not required.

Node-Webkit won't open file

First I'd like to say thanks for taking the time to read this.
I am trying to open a JSON file that is in the following directory structure:
#--> Root Folder
--> App.exe
#--> Configuration
---> JSON File
So I used the Code:
var ConfigFile = "./Configuration/JSON.json";
Followed by:
var fs = require('fs');
var file_content = fs.readFileSync(ConfigFile);
var content = JSON.parse(file_content);
// Manipulate the Data
For some odd reason, Node-Webkit seems to be looking for the folder in a Temp Directory located in:
C:\Users\User\AppData\Local\Temp\nw9740_14956\Configuration
The file is not there, and thus in the Console I get the following Error:
Uncaught Error: ENOENT: no such file or directory, open
'C:\Users\User\AppData\Local\Temp\nw9740_14956\Configuration\JSON.json'
I am running Windows (as you can tell), and I would like for fs to pull the file from the Folder (Configuration) that is adjacent to the app.exe.
Any help is appreciated
I've only done this once, so I may be wrong, but it looks like you're bundling your app content into the exe? If you do this, node-webkit will extract the app contents into the %TEMP% folder and then run the content from there.
Try checking the command line arguments to see if arg[0] will point you to the actual node-webkit exe that's running the app. From there, you should be able to construct a path to your configuration data.

How to upload folder in php

Hi i wanted to upload folder and move to some destination is it possible doing in php ? or at least i can read the folder name and create same folder in divination and copy all files into created folder.
You can do this with the new HTML5 directory capabilities. Just put the directory attributes in your input field. After you got the directory server-side, you can do everything you want with it.
URL for a simple guide:
http://www.w3bees.com/2013/03/directory-upload-using-html-5-and-php.html

ajax call to a local csv file

The folder structure is:
HOME\htmlhelp\wwhelp\wwhimpl\js\scripts
HOME\auxi\
I can read a csv file (located in the HOME\htmlhelp dir) from a js file located in the HOME\htmlhelp\wwhelp\wwhimpl\js\scripts dir using the following:
var file_path="../../../../../htmlhelp/rule_mapping.csv";
However, the same js file (from the same location) cannot read the same csv file in the HOME\auxi\ directory!
Am using the path as var file_path="../../../../../auxi/rule_mapping.csv";
It throws an "NS_ERROR_DOM_BAD_URI: Access to restricted URI denied" error. I have checked the file permissions and stuff but no luck.
Any help would be appreciated.
The problem lies within:
var file_path="../../../../../htmlhelp/rule_mapping.csv";
It's not possible to traverse up to paths out of the root directory where the document is located.
Assuming you work under UNIX (Linux/Mac), one solution would be to create a symbolic link on the root directory of the document, such as (executing from the scripts directory):
ln -s ../../../../../htmlhelp/rule_mapping.csv rule_mapping.csv
And changing the file_path to:
var file_path="./rule_mapping.csv";
I hope this helps!

How to src to a file in a folder within a folder

Hi I'm pretty new to HTML and JavaScript and I was wondering how to src to a file in a folder within a folder?
Any help would be appreciated.
To be more specific I'm trying to access a JavaScript library in a folder named yui and which is another folder named libraries.
<script src='./folderwithinfolder/file.js'></script>
To break it down:
./ = folder this file is in.
folderwithinfolder/= A folder within the folder the webpage is in.
file.js = Javascript File.
You can change the SRC to follow where you want to go the folders:
libraries/yui/your-library-name-here.js

Categories

Resources