This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
Closed 3 years ago.
I have a problem I call the function (showpincode()) but the value is not working can you help me. I call it using backend but the value (txtRequestEncrypted.text) did not work
BACKEND C#
List<Upload> c = new List<Upload>();
c.Add(b);
a.UploadCardDetails = c;
a.ProgramName = null;
a.IPAddress = "111.222.33.444";
a.Authentication = "Basic RXFNzdzw==";
object obj = a;
string test = JsonConvert.SerializeObject(obj);
string pkey = "test";
string psalt = "test1";
string Result = Utilities.Utilities.test1(test, pkey, psalt);
txtRequestEncrypted.Text = Result.ToString();
this.Controls.Add(new LiteralControl("<script type='text/javascript'>ShowPINPad();</script>"));
JAVASCRIPT VALIDATION TO ACCESS THE PINCODE
<script type="text/javascript">
window.addEventListener("message", function (ev) {
"https://testtest.com.ph/index"
//event origin of virtual pin pad
$origin = ev.origin;
//event source of virtual pin pad
$source = ev.source;
//IMPORTANT: CHECK THE ORIGIN OF THE DATA!
if (ev.origin.indexOf($sourceURL)) {
if (ev.data.message === "deliverResult") {
ev.source.close();
}
else if (ev.data.message == "RESEND") {
txtResponse
try {
setTimeout(function () {
var requestData = $('#<%= txtRequestEncrypted.ClientID %>').val();
child.postMessage({ message: "requestResult", encryptedRequestData: requestData}, "*");
}, 3000);
} catch (e) {
//checking the virtual pin pad is closed
if (child.closed) {
console.log('Error encountered when calling virtual pinpad...');
clearTimeout(interval);
//do something
document.getElementById("txtResponse").value = "CLOSED";
document.getElementById("txtResponseEncrypted").value = "";
return;
}
}
}
}
});
THIS IS THE FUNCTION to Show Pinpad
var child = null;
function ShowPINPad() {
var height = 406;
var width = 450;
var left = Math.round((screen.width / 2) - (width / 2));
var top = Math.round((screen.height / 2) - (height / 2));
var targetURL = "https:test.com.ph/index"
child = window.open(targetURL, "_blank", "scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,directories=no,copyhistory=no,height=" + height + ",width=" + width + ",left=" + left + ",top=" + top + ";");
// child.focus();
}
Page.ClientScript.RegisterStartupScript(this.GetType(),"CallMyFunction","MyFunction()",true);
check more Details On This Link
Calling JavaScript Function From CodeBehind
Please follow below code to call javascript function from code behind:
string jquery = "drawImage();"
ClientScript.RegisterStartupScript(typeof(Page), "a key",
"<script type=\"text/javascript\">"+ jquery +"</script>"
);
For more details:
Call javascript function from code behind
Related
From my api provider i have a code thats suposed to generate a hmac key.
<html>
<head>
</head>
<body>
<p id="demo"></p>
<script>var BuckarooHmac = (function () {
var self = {};
function getEncodedContent(content) {
if (content) {
var md5 = CryptoJS.MD5(content);
var base64 = CryptoJS.enc.Base64.stringify(md5);
return base64;
}
return content;
}
function getHash(websiteKey, secretKey, httpMethod, nonce, timeStamp, requestUri, content) {
var encodedContent = getEncodedContent(content);
var rawData = websiteKey + httpMethod + requestUri + timeStamp + nonce + encodedContent;
var hash = CryptoJS.HmacSHA256(rawData, secretKey);
var hashInBase64 = CryptoJS.enc.Base64.stringify(hash);
return hashInBase64;
}
function getTimeStamp() {
return Math.floor((new Date).getTime() / 1000);
}
function getNonce() {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < 16; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
}
self.GetAuthHeader = function (requestUri, websiteKey, secretKey, content, httpMethod) {
var nonce = getNonce();
var timeStamp = getTimeStamp();
content = content ? content : "";
var url = encodeURIComponent(requestUri).toLowerCase();
return "hmac " + websiteKey + ":" + getHash(websiteKey, secretKey, httpMethod, nonce, timeStamp, url, content) + ":" + nonce + ":" + timeStamp;
}
return self;
document.getElementById("demo").innerHTML = self.GetAuthHeader();
}());
</script>
</body>
</html>
I'm not used to javascript. I'm trying to figure out how to print the generated key on my screen. I tried this :
document.getElementById("demo").innerHTML = self.GetAuthHeader();
I know i must be doing this wrong. I just need a push in the right direction now. Anyone that could help me ?
You’re trying to perform an action after the function’s return statement. That code will never be reached because the function has returned.
Instead, do it before:
document.getElementById("demo").innerHTML = self.GetAuthHeader();
return self;
Or, even better, if this code is provided by a vendor then you probably shouldn’t edit it. Updates would remove your edits, and vendor support would be compromised. Instead, perform your action outside the code entirely:
var BuckarooHmac = (function () {
// vendor code
}());
document.getElementById("demo").innerHTML = BuckarooHmac.GetAuthHeader();
Hello you wonderful people, I am trying to build JavaScript file to extract information from Wikipedia based on search value in the input field and then display the results with the title like link so the user can click the link and read about it. So far I am getting the requested information in(JSON)format from Mediawiki(Wikipedia) but I can't get it to display on the page. I think I have an error code after the JavaScript array.
I'm new at JavaScript any help, or hint will be appreciated.
Sorry my script is messy but I am experimenting a lot with it.
Thanks.
var httpRequest = false ;
var wikiReport;
function getRequestObject() {
try {
httpRequest = new XMLHttpRequest();
} catch (requestError) {
return false;
}
return httpRequest;
}
function getWiki(evt) {
if (evt.preventDefault) {
evt.preventDefault();
} else {
evt.returnValue = false;
}
var search = document.getElementsByTagName("input")[0].value;//("search").value;
if (!httpRequest) {
httpRequest = getRequestObject();
}
httpRequest.abort();
httpRequest.open("GET", "https://en.wikipedia.org/w/api.php?action=query&format=json&gsrlimit=3&generator=search&origin=*&gsrsearch=" + search , true);//("get", "StockCheck.php?t=" + entry, true);
//httpRequest.send();
httpRequest.send();
httpRequest.onreadystatechange = displayData;
}
function displayData() {
if(httpRequest.readyState === 4 && httpRequest.status === 200) {
wikiReport = JSON.parse(httpRequest.responseText);//for sunchronus request
//wikiReport = httpRequest.responseText;//for asynchronus request and response
//var wikiReport = httpRequest.responseXML;//processing XML data
var info = wikiReport.query;
var articleWiki = document.getElementsByTagName("article")[0];//creating the div array for displaying the results
var articleW = document.getElementById("results")[0];
for(var i = 0; i < info.length; i++)
{
var testDiv = document.createElement("results");
testDiv.append("<p><a href='https://en.wikipedia.org/?curid=" + query.pages[i].pageid + "' target='_blank'>" + query.info[i].title + "</a></p>");
testDiv.appendChild("<p><a href='https://en.wikipedia.org/?curid=" + query.info[i].pageid + "' target='_blank'>" + query.info[i].title + "</a></p>");
var newDiv = document.createElement("div");
var head = document.createDocumentFragment();
var newP1 = document.createElement("p");
var newP2 = document.createElement("p");
var newA = document.createElement("a");
head.appendChild(newP1);
newA.innerHTML = info[i].pages;
newA.setAttribute("href", info[i].pages);
newP1.appendChild(newA);
newP1.className = "head";
newP2.innerHTML = info[i].title;
newP2.className = "url";
newDiv.appendChild(head);
newDiv.appendChild(newP2);
articleWiki.appendChild(newDiv);
}
}
}
//
function createEventListener(){
var form = document.getElementsByTagName("form")[0];
if (form.addEventListener) {
form.addEventListener("submit", getWiki, false);
} else if (form.attachEvent) {
form.attachEvent("onsubmit", getWiki);
}
}
//createEventListener when the page load
if (window.addEventListener) {
window.addEventListener("load", createEventListener, false);
} else if (window.attachEvent) {
window.attachEvent("onload", createEventListener);
}
Mediawiki api link
https://en.wikipedia.org/w/api.php?action=query&format=json&gsrlimit=3&generator=search&origin=*&gsrsearch=
You are wrong some points.
1)
var articleW = document.getElementById("results")[0];
This is wrong. This will return a element is a reference to an Element object, or null if an element with the specified ID is not in the document. Doc is here (https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById)
The correct answer should be :
var articleW = document.getElementById("results");
2)
var info = wikiReport.query;
for(var i = 0; i < info.length; i++) {}
The info is object . it is not array , you can't for-loop to get child value.
wikiReport.query is not correct wiki data. The correct data should be wikiReport.query.pages. And use for-in-loop to get child element
The correct answer:
var pages = wikiReport.query.pages
for(var key in pages) {
var el = pages[key];
}
3) This is incorrect too
testDiv.appendChild("<p><a href='https://en.wikipedia.org/?curid=" + query.info[i].pageid + "' target='_blank'>" + query.info[i].title + "</a></p>");
The Node.appendChild() method adds a node to the end of the list of children of a specified parent node. You are using the method to adds a string . This will cause error. Change it to node element or use append method instead
I have created a sample test.You can check it at this link below https://codepen.io/anon/pen/XRjOQQ?editors=1011
Working on a script for InDesign I found this problem : if I call app.open() from inside button.onclick() it stops and nothing happens.
Since I'm a beginner with Javascript I'm probably doing something wrong. But if not, how do I fix? I can not find an alternative.
Please, only pure Javascript.
Thanks in advance.
Here the working code :
var book_info;
if (app.books.length != 1) {
var theFile = File.openDialog ("Select the book file to open...");
get_data(theFile);
alert(book_info.filePath + "\r" + book_info.name);
}
book_info.close();
function get_data(data) {
app.open(data);
book_info = app.activeBook;
alert("INSIDE FUNCTION" + book_info.filePath + "\r" + book_info.name);
return data;
}
and here the one not working :
var book_info;
var w1 = new Window ("dialog", "TEST");
w1.minimumSize.height = 50;
w1.minimumSize.width = 50;
var p1 = w1.add ("panel");
sel_button = p1.add ("button", undefined, "Select book");
var g1 = w1.add ("group");
g1.add("button", undefined, "Cancel");
g1.add("button", undefined, "OK");
sel_button.onClick = function(){
var theFile = File.openDialog ("Select the book file to open...");
get_data(theFile);
alert(book_info.filePath + "\r" + book_info.name);
book_info.close();
};
w1.show();
function get_data(data) {
app.open(data);
book_info = app.activeBook;
alert("INSIDE FUNCTION" + book_info.filePath + "\r" + book_info.name);
return data;
}
There is an alternative answer at app.open not responding if called from inside onclick()
It also suggested the use of 'palette' window instead of modal dialogue
Try this:
var book_info;
var theFile;
var getData;
var w1 = new Window ("dialog", "TEST");
w1.minimumSize.height = 50;
w1.minimumSize.width = 50;
var p1 = w1.add ("panel");
sel_button = p1.add ("button", undefined, "Open a book");
var g1 = w1.add ("group");
g1.add("button", undefined, "Cancel");
g1.add("button", undefined, "OK");
sel_button.onClick = function(){
theFile = File.openDialog ("Select the book file to open...");
getData =1;
w1.close(1);
};
w1.show()
if ( getData ==1) {
if ( theFile ) {
get_data(theFile);
}
}
function get_data(data) {
app.open(data);
book_info = app.activeBook;
alert("INSIDE FUNCTION" + book_info.filePath + "\r" + book_info.name);
return data;
}
I want to show a loading icon while a task is being performed and then hide the icon after it has been performed. I need to use a web worker for the loading icon to show. The admin at This forum post said to use a web worker.
This is the code to execute in the web worker:
function getTheClients(xml) {
console.log(xml);
var client = xml.getElementsByTagName("WebClientList");
if(client.length === 0) {
$("#noClients" + platform).empty();
$("#noClients" + platform).append('<p style="margin-top:40px;margin-bottom:20px;text-align:center;">No clients at ' +
getSelectedDropDownOptionName("allVillagesDropDown") + ', ' +
getSelectedDropDownOptionName("allLocationsDropDown") + '.</p>');
$("#noClients" + platform).attr("style", "display: block");
$("#theClientsList" + platform).attr("style", "display: none");
} else {
$("#noClients" + platform).attr("style", "display: none");
$("#theClientsList" + platform).attr("style", "display: block");
}
for (i=0; i < client.length; i++) {
var firstName = client[i].getElementsByTagName("givenName")[0].childNodes[0];
var lastName = client[i].getElementsByTagName("familyName")[0].childNodes[0];
var oid = client[i].getElementsByTagName("oid")[0].childNodes[0];
var nhi = client[i].getElementsByTagName("nhi")[0].childNodes[0];
var dwelling = client[i].getElementsByTagName("dwelling")[0].childNodes[0];
var photo = client[i].getElementsByTagName("photo")[0].childNodes[0];
if (!photo) {
photo = "";
} else {
photo = photo.nodeValue;
}
firstName = firstName ? firstName.nodeValue : "";
lastName = lastName ? lastName.nodeValue : "";
oid = oid ? oid.nodeValue : "";
nhi = nhi ? nhi.nodeValue : "";
dwelling = dwelling ? dwelling.nodeValue : "";
var letterDwelling = dwelling ? dwelling[0].toUpperCase() : "";
var letterLastName = lastName ? lastName[0].toUpperCase() : "";
console.log(photo);
dataSource.add({photo: photo, firstName: firstName,lastName: lastName,oid: oid,nhi: nhi,dwelling: dwelling, letterDwelling: letterDwelling, letterLastName: letterLastName});
}
if (clientListViewHasNotLoaded) {
searchFilter = "lastName";
listGroup = "letterLastName"
console.log("e");
$("#theClientsList" + platform).append('<ul id="flat-listview' + platform + '" class="listView' + platform + '" style="width: 100%; margin-bottom:10px; margin-top:10px;"></ul>');
initListView({
field: "lastName",
operator: "startswith",
placeholder: "Search by last name"
}
);
$("#flat-listview" + platform).data("kendoMobileListView").setDataSource(dataSource);
clientListViewHasNotLoaded = false;
}
}
here is the code I'm using to create a web worker, before I take the next step and incorporate my above function:
the script (webServiceScript.js):
self.onmessage = function(event) {
var results = event.data;
// do something
// Done:
postMessage(results);
};
The calling code:
var worker = new Worker('scripts/webServiceScript.js');
worker.onmessage = function(event) {
// Do something with event.data, then hide the spinner.
app.showLoading();
};
app.hideLoading();
worker.postMessage({args: ' foo bar '});
I would like to incorporate my function at the top of the question into the script file (to be used in a web worker). When I incorporate my above function into the script, I need to pass my variable called xml.
Any help greatly appreciated, I'm struggling to understand the documentation here.
As we were discussing in comments, all you need to do is give the browser a chance to do a repaint. You can accomplish that with setTimeout() like this:
app.showLoading()
setTimeout(function() {
getTheClients(xml);
app.hideLoading();
}, 1);
You can't do setTimeout(getTheClients(xml), 1); because that calls getClients() right away and then passes the return result from that to setTimeout(). Instead, you have to pass just a function reference to setTimeout() as shown above.
This is a mvc 3 razor vb.net application... I have the code behind doing everything fine so I decided to add a little more to the data coming in to the java so that the screen could be a little more informative about it's current progress... The string that getstatus has coming in is a string delimited with "/" where data.split("/")(0) = the integer in the function and data.split("/")(1) = the string to display in the currentEmail div... This is not working and it is simply because I am a total noob to javascript and i know it is possible..
#Code
ViewData("Title") = "MassEmailSendingStatus"
TempData.Add("emList", TempData("emailaddresses"))
Dim x As String = Guid.NewGuid().ToString
end Code
<div>
Start Process
</div>
<br />
<div id="currentEmail">
</div>
<div id="statusBorder">
<div id="statusFill">
</div>
</div>
<script type="text/javascript">
var uniqueId = '#x';
var tdata = '#TempData("emailaddresses")';
$(document).ready(function (event) {
$('#startProcess').click(function () {
$.post("MassEmailSendingStatus", { id: uniqueId }, function () {
$('#statusBorder').show();
getStatus();
});
event.preventDefault;
});
});
function getStatus() {
var url = 'GetCurrentProgress/' + uniqueId;
$.get(url, function (data) {
var str = data;
var n1 = str.split("/");
var v1 = integer.parseint(n1[0]);
var v2 = n1[1];
if (v1 != "100") {
$('#status').html(data);
$('#currentEmail').html(v2);
$('#statusFill').width(v1);
window.setTimeout("getStatus()", 100);
}
else {
$('#status').html("Done");
$('#statusBorder').hide();
alert("The Long process has finished");
};
});
}
</script>
Found it on my own with some browser lvl debugging..
var v1 = integer.parseint(n1[0]); is wrong it should be var v1 = ParseInt(n1[0]); case sensitive languages = not for noobs like meh.
function getStatus() {
var url = 'GetCurrentProgress/' + uniqueId;
$.get(url, function (data) {
var str = data;
var n1 = str.split("/");
var v1 = integer.parseint(n1[0]);
var v2 = n1[1];
if (v1 != "100") {
$('#status').html(data);
$('#currentEmail').html(v2);
$('#statusFill').width(v1);
window.setTimeout("getStatus()", 100);
}
else {
$('#status').html("Done");
$('#statusBorder').hide();
alert("The Long process has finished");
};
});
}