I have some routine task (change some column types in MSSQL) on multiple server.
So, I'm trying to make a script program that connects to MSSQL and change structure of some tables.
What I've done so far...
I made a text file on Desktop and wrote the code below in the file
<!DOCTYPE html>
<html>
<head>
<script>
var objConnection = new ActiveXObject("adodb.connection");
var strConn = "driver={sql server};server=192.168.139.121;database=mytest;uid=testuser;password=testpw";
objConnection.Open(strConn);
var rs = new ActiveXObject("ADODB.Recordset");
(queries for changing table structure)..
</script>
</head>
<body>
</body>
After that, I saved it as HTML file and executed it with Internet Explorer.
But, No response.. I found that after executing 'objConnection.Open(strConn);' IE waits for response forever.. Is there any library or program to be installed to execute all the code above? please give me some hints
You can try this (Works only in IE) :
<!DOCTYPE html>
<html>
<head>
<script>
var connection = new ActiveXObject("ADODB.Connection") ;
var connectionstring="Data Source=<server>;Initial Catalog=<catalog>;User ID=<user>;Password=<password>;Provider=SQLOLEDB";
connection.Open(connectionstring);
//your queries here
rs.close;
connection.close;
</script>
</head>
<body>
</body>
</html>
You really shouldn´t use client side script like javascript to access databases for several reasons like bad practice, security issues etc. You can use .Net, PHP, JAVA etc which are server side language and better way to use these to interact with the databases.
Related
I was trying to use the document.getElementbyId() but when I run the console it tells me it is not defined.
My index.html and index.js are in the same folder the source should be OK.
I'm using Cmd + Shift + P in Visual Studio Code and then choose "Run: without debbuging". The error message shows in the integrated console.
let word1 = "Alex";
let word2 = "Toko";
let example = `${word1} ${word2}`;
var doc = document.getElementById("test").innerText = example;
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<p id="test"> </p>
<script src="index.js"> </script>
</body>
</html>
The issue is the waqy you're running the code.
cmd+shift+P will run the index.js on it's own, and it won't know or care about the html.
Instead, open the html in your browser, and it should work.
The reason it won't work on vs code is that it runs the javascript file directly, and while the html links to the javascript, it won't work the other way around.
cmd+shift+P is used for server-side javascript, not client side. client side, you can just test in browser.
I need an advice how to dynamically change HTML data.
My web page will have some form, which will call a PHP function, which I am planing to return JSON array (I can accept also other output, except raw HTML).
Than i want the page content to be replaced with the JSON values.
The idea of that is to have the HTML code separated from the PHP function.
Can you please tell me if this is a good practice and if yes, can you please give me some example ?
Thanks in advice !
Yes it is actually a good practice - I do this every day .
See the web is fast advancing and the more we separate concerns the more flexible we get . Now here are the facts :
With the introduction of Progressive Web Apps , creating an app shell
(Basically a skeleton of the website without data) is recommended so
that new data is loaded from ajax/fetch see this link
Imagine when you want to do a tv version of your website/webapp - you
will only need to create an app shell where the JSON data will be
used to fill in the data
I advocate for separation of concerns since it will be much easier to add more platform & device support since you will only be worried about the template / shell and not the data
Here is an example :
filename/url : localhost:8080/index.php
<?php
$myObj->name = "John";
$myObj->age = 30;
$myObj->city = "New York";
$myJSON = json_encode($myObj);
echo $myJSON;
?>
Then on the client side
index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery.getJSON demo</title>
<style>
#userInfo{
height: 100px;
float: left;
}
</style>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<div id="userInfo"></div>
<script>
(function() {
var myUrl = "https://localhost:8080/index.php";
$.getJSON( myUrl)
.done(function( data ) {
/*
{"name":"John","age":30,"city":"New York"}
*/
var userInfo = document.getElementById('userInfo');
userInfo.innerHTML = '<p>Name :'+ data.name +'</p>
<p>Age:'+ data.age+'</p>
<p>City:'+ data.city+'</p>';
});
})();
</script>
</body>
</html>
I get "ReferenceError: SpreadsheetApp is not defined" when i run the above code. Is there any error?
This is working in script editor but not working in separate file
<html>
<head>
<title>Site</title>
</head>
<body>
<p id="demo"></p>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script>
var ss = SpreadsheetApp.openById('1-wYHx2ynT1fMAUKHSeRDBABjE_cAbJ2tfBP_deKjhGs');
document.getElementById("demo").innerHTML =ss.getName();
</script>
</body>
</html>
Take a look at the Google Apps Script tutorials. For the most part, GAS is all server-side scripting, whereas you're trying to gain client-side access to a spreadsheet. It doesn't work like that. You'll need to follow one of the tutorials and open the script editor to begin writing your code.
You need to redirect call function in a way html apps script allows you. Please have a look at simple line below, which permits you to access any function
a file called "lookatme.html"
</script>
function doStuff() {
google.script.run.doStuff()
console.log("ggg")
}
</script>
if it is a .gs extension file unlike html file, it will recognize the code below and any extended apps scripts' built-in functions
a file called "anyfile.gs"
function doStuff() {
console.log("ggg")
// google.script.run.userClicked(userInfo)
var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1i9of_RcoDih65x2h7-agSdCaUSvc1fvfOm4Y7dQEb-s/edit#gid=0")
var ws = ss.getSheetByName("Data")
ws.appendRow(["name"])
}
I am required to remotely include into my appcelerator project, a javascript file available at a particular link, and use the function declared in that file to process some data.
What i would like to achieve is something like the following in html -
<script src="https://some-link/Data.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
var testVariable = someMethod(localdata);
});
//use testVariable as necessary
</script>
//someMethod() is declared in remotely available Data.js
I am a newb at Appcelerator and im not really able to follow some of the threads i have come across, so some detailed help would be really appreciated. Thank you in advance.
Well according to me , you should first understand few points first :
You want to include a remote file hosted at some server , now as the Titanium code converts to native code at compile time , you cannot include Titanium API's from remote file.
If you want to include a remote file , then only option which I see is loading that file in webview.
Now coming to your problem , as you said that you want to fetch some data only from remote server by triggering some JS function from remote file. So following is what would I do :-
a/ Create a hidden webview in my main window with a EventListener of webview. Something like :
var webview = Titanium.UI.createWebView({url:'localHtmlFile.html'});
//event listener to handle the response from webview
Ti.App.addEventListener('fromWebView', function(e)
{
var testVariable = e.data;
});
b/ In localHtmlFile.html file :
<!DOCTYPE html>
<html>
<body>
<script src="https://some-link/Data.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
var testVariable = someMethod();
//respond the fetch data to the main window via fireEvent
Ti.App.fireEvent( 'fromWebView', { data : testVariable } );
});
</script>
</body>
</html>
PS : This is just a logic to begin with , you have to edit code according to your requirements
I have java script file that reads in a csv file, and has many functions to to visualize the data differently, using d3. I want each visualization to be displayed in different html pages. Ive made every html page, refer to the javascript file. Each page also has its own script that calls functions from the referred javascript file.
The problem, I am facing is that when ever I go to a new page, the function gets called before the data being read. Only works when refreshing the page. I there a way to just read the data in once, and every page can access it.
If you look at the code below, callingFunction() returns undefined (maybe because data is not stored in var data?) The callingFunction() works fine when the page is refreshed.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>D3</title>
**<script src="my.js"></script>** //my script file
</head>
<body>
<script>
callFunction(); //uses var data defined in my.js
</script>
Here is the "my.js":
var data;
function data(file){d3.csv("file", function (error, data) {
ds = data;
callFunction();
}
load your script after the target DOM :
<canvas></canvas>
...........................
<script type="text/javascript"></script>
Use angularJs Js library: it organize your js code according to MVC design pattern.
If you have more than one method to implement a business logic , Use console.time & console.timeEnd to evaluate code performance .
console.time('anID');
// Here your code
console.timeEnd('anID');