I am currently using a calender system that has an API I can access with SOAP requests. It exists on an IIS server.
Initially I figured I could create an HTML page that that I would then have use Javascript to return the contents of the SOAP request - and my SOAP requests returns exactly what I want it to, but not in valid XML - it just displays on the screen (currently commented out below).
What I need to know is how do I get a page to return just the valid XML response (and no other tags, so it is recognized as XML)? Would PHP be better suited for this - or ASP?
My current javascript looks like this:
function soap() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open('POST', 'http://myserver/EMSAPI/', true);
//Todays Date now = new Date();
year = "" + now.getFullYear();
month = "" + (now.getMonth() + 1); if (month.length == 1) { month = "0" + month; }
day = "" + now.getDate(); if (day.length == 1) { day = "0" + day; }
hour = "" + now.getHours(); if (hour.length == 1) { hour = "0" + hour; }
minute = "" + now.getMinutes(); if (minute.length == 1) { minute = "0" + minute; }
second = "" + now.getSeconds(); if (second.length == 1) { second = "0" + second; }
todaydate = year + "-" + month + "-" + day + "T" + hour + ":" + minute + ":" + second + ".000";
// build SOAP request
var sr =
'<?xml version="1.0" encoding="utf-8"?>' +
'<soap:Envelope ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xmlns:api="http://127.0.0.1/Integrics/Enswitch/API" ' +
'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' +
'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
'<soap:Body>' +
'<GetAllBookings xmlns="http://DEA.EMS.API.Web.Service/">' +
'<UserName>EmsAPI</UserName>' +
'<Password>Mypass</Password>' +
'<StartDate>'+todaydate+'</StartDate>' +
'<EndDate>'+todaydate+'</EndDate>' +
'<BuildingID>36</BuildingID>' +
'<ViewComboRoomComponents>false</ViewComboRoomComponents>' +
'</GetAllBookings>' +
'</soap:Body>' +
'</soap:Envelope>';
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
ret = xmlhttp.responseText;
//$(document.body).append(ret);
}
}
}
// Send the POST request
xmlhttp.setRequestHeader('Content-Type', 'text/xml');
xmlhttp.send(sr);
// send request
// ...
}
window.onload = function() { soap(); };
My HTML is very straight forward - it is a blank document besides including the javascript.
The problem is I'm using some software that cannot interface with the calender directly - and that software will only accept a valid XML response - so whatever page I write, it has to return just the pure XML so that way when I tell the software the page URL - it is given the XML response appropriately.
Just wondering what other ways there may be to go about this to get it to work. I apologize if the question is confusing - I can elaborate if needed.
I went with Classic ASP in order to do what I wanted it to.
My final code looked like this in classic ASP:
<%
Dim objXMLHTTP : set objXMLHTTP = Server.CreateObject("MSXML2.XMLHTTP")
Dim strRequest, strResult, strFunction, strURL, strNamespace
'URL to SOAP namespace and connection URL
strNamespace = "http://DEA.EMS.API.Web.Service/"
strURL = "http://myserver/EMSAPI/"
'function you want to call
strFunction = "GetBuildings"
'strFunction = "test" 'no parameters required
strRequest ="<?xml version=""1.0"" encoding=""utf-8""?>" &_
"<soap:Envelope" &_
" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""" &_
" xmlns:api=""http://127.0.0.1/Integrics/Enswitch/API""" &_
" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""" &_
" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">" &_
"<soap:Body>" &_
"<GetBuildings xmlns=""http://DEA.EMS.API.Web.Service/"">" &_
"<UserName>Myusername</UserName>" &_
"<Password>mypassword</Password>" &_
"</GetBuildings>" &_
"</soap:Body>" &_
"</soap:Envelope>"
objXMLHTTP.open "POST", ""& strURL &"", True
objXMLHTTP.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
objXMLHTTP.setRequestHeader "Content-Length", Len(strRequest)
objXMLHTTP.setRequestHeader "SOAPAction", strNamespace & strFunction
'send the request and capture the result
objXMLHTTP.send(strRequest)
'Set a timer to wait for response
set shell = CreateObject("WScript.Shell")
t1 = timer()
sleep(1)
t2 = timer()
response.write "waited "& t2-t1 &" secs"
function sleep(seconds)
if seconds>=1 then shell.popup "pausing",seconds,"pause",64
end function
strResult = objXMLHTTP.responseText
'display the XML
response.write strResult
%>
Related
I have a javascript program with filesystem (saves user answer,etc) The file name I have implemented data and time however if the user repeats the program, and after that ends it. All the file will be saved with the same time
Tried putting it into a string. After the file system does it job, i clears the string. Which is suppose to work? because it will check for new local time.
function filesystem() {
var date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate(); //gets local machine year,date,time.
var time = today.getHours() + "Hour." + today.getMinutes() + " Min." + today.getSeconds() + " Seconds";
var dateTime = parseFloat("Date " + date + ' ' + "Time " + time);
var dateTimestr= "";
dateTimestr += (dateTime);
fs.writeFile("CA2/Quizresults/" + fullname + " " + categorystorage + " " + dateTimestr + ".txt", summarystring + "Your score is " + point + "/5.", (err) => {
if (err) throw err;
})
console.log('Saved!'); //when saved successfully. it will prompt the user.
point = 0; //Sets point as 0. so the point does not bring forward to the next user.
lifelinecounter = 0; //Sets lifelinecounter as 0. so the lifelinecounter does not bring forward to the next user.
summarystring = "";
dateTimestr =""; //Sets summarystring as empty. so the summarystring does not bring forward to the next user.
}
All the files saves with the same time in the file name
var today = new Date();
Please add the above as the first statement of the function. You have assigned today outside the function, and it's value is not going to change according to the running time. If you want current date, you will have to call new Date() again and assign it to your today variable.
So you bound the today variable to a new Date()
var today = new Date() // right?
now when filesystem function runs, it's looking at that variable, and that variable holds the same value forever from the moment when you initialize it.
So you need to reassign value at the beginning of the function like this:
function filesystem() {
today = new Date()
var date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate(); //gets local machine year,date,time.
var time = today.getHours() + "Hour." + today.getMinutes() + " Min." + today.getSeconds() + " Seconds";
var dateTime = parseFloat("Date " + date + ' ' + "Time " + time);
var dateTimestr= "";
dateTimestr += (dateTime);
fs.writeFile("CA2/Quizresults/" + fullname + " " + categorystorage + " " + dateTimestr + ".txt", summarystring + "Your score is " + point + "/5.", (err) => {
if (err) throw err;
})
console.log('Saved!'); //when saved successfully. it will prompt the user.
point = 0; //Sets point as 0. so the point does not bring forward to the next user.
lifelinecounter = 0; //Sets lifelinecounter as 0. so the lifelinecounter does not bring forward to the next user.
summarystring = "";
dateTimestr =""; //Sets summarystring as empty. so the summarystring does not bring forward to the next user.
}
I am having a problem when attempting to echo data in a php file to mobile Safari in iOS 7.1.2. Here is the php code:
function swapFlights()
{
var url;
redirect = 1;
airline = <?php echo 'PDT'; ?>;
url = "swap.php?date_one=" + date1 + "&flight_number_one=" + flight1 + "&dep_station_one=" + city1 + "&date_two=" + date2 + "&flight_number_two=" + flight2 + "&dep_station_two=" + city2 + "&redirect=" + redirect + "&airline=" + airline;
window.location.href = url;
}
In mobile Safari on iPhone 5S, the output is the following:
function swapFlights()
{
var url;
redirect = 1;
airline =
2cc1
PDT;
url = "swap.php?date_one=" + date1 + "&flight_number_one=" + flight1 + "&dep_station_one=" + city1 + "&date_two=" + date2 + "&flight_number_two=" + flight2 + "&dep_station_two=" + city2 + "&redirect=" + redirect + "&airline=" + airline;
window.location.href = url;
}
The seemingly random "2cc1" is interjected, and I cannot for the life of me figure out why. It causes a SyntaxError in the parsing of the JavaScript, rendering all of the JavaScript on the page unusable. In every other browser I've tried (desktop Safari, Firefox), the code is output correctly as one would expect:
function swapFlights()
{
var url;
redirect = 1;
airline = PDT;
url = "swap.php?date_one=" + date1 + "&flight_number_one=" + flight1 + "&dep_station_one=" + city1 + "&date_two=" + date2 + "&flight_number_two=" + flight2 + "&dep_station_two=" + city2 + "&redirect=" + redirect + "&airline=" + airline;
window.location.href = url;
}
Any ideas, or is this more likely a bug in mobile Safari itself? I've searched all over the internet, but can't seem to find any other instances of this problem.
Changing the php to:
redirect = 1;
<?php echo 'airline = PDT'; ?>;
results in the unknown characters being slightly different, and appearing earlier in the output:
redirect = 1;
2ccb
airline = PDT;
I should have specified that my goal is the replace the 'PDT' with the string variable $airline. I changed the variable to the literal 'PDT' thinking I may have had a problem with the datatype of the variable, but that wasn't the case.
i would like to insert variables into my database, some are php wich works fine, but the problem is the javascript variables, it does not work. im quite new to this any help would be nice.
this is my first question, im sorry if i get the code blocks wrong.
echo '<br>
<form><input type="button" id="startbutton" value="start time control" onClick="starttime()" style="width:225px; margin-top:0px; "><br>
<script type="text/javascript">
var tekst = "";
var startdatum;
var starttijd;
var stopdatum;
var stoptijd;
var startdatumtijd;
function starttime()
{
var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth() + 1;
var curr_year = d.getFullYear();
starttijd = d.getHours() + ":" + d.getMinutes();
startdatum=(curr_year + "-" + curr_month + "-" + curr_date);
startdatumtijd = (startdatum + " " + starttijd);
startbutton.value = "stop timecontrol";
startbutton.onclick = timecontrol;
}
function timecontrol()
{
var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth() + 1;
var curr_year = d.getFullYear();
tekst = document.getElementById("inputtekst").value;
stoptijd = d.getHours() + ":" + d.getMinutes();
stopdatum=(curr_year + "-" + curr_month + "-" + curr_date);
var stopdatumtijd = (stopdatum + " " + stoptijd);
tx.executeSql("INSERT INTO `vtiger_timecontrol` (`title`,`relconcept`, `relatedto`, `date_start`,`time_start`,`date_end`,`time_end`)VALUES ('.$ticketno.' , \'Support_\' , '.$ticketnummer.' , startdatum , starttijd , einddatum , eindtijd );");
tx.executeSql("INSERT INTO `vtiger_crmentity` (`description`,`setype`,`createdtime`,`modifiedtime`,`viewedtime`)VALUES(tekst,\'Timecontrol\',stopdatumtijd,stopdatumtijd,stopdatumtijd);");
}</script></form>';
What should happen is when i press a button, it saves the time in a variable, the second time i press the button it will save the time in another variable, now i want these time variables to be saved in my database.
Thank you.
ajax worked:
if (radio2.checked == true)
{
var checked = 0;
xmlhttp = new XMLHttpRequest();
xmlhttp.open("post","tc.php?ticketid='.$ticketnummer.'&ticketnummer='.$ticketno.'&hidden1=" + startdatum+"&hidden2=" + starttijd+"&hidden3=" + stopdatum+"&hidden4=" + stoptijd+"&hidden5=" + tekst+"&hidden6=" + stopdatumtijd + "&hidden7=" + checked, false);
xmlhttp.send();
}
else if (radio3.checked == true)
{
var checked = 1;
xmlhttp = new XMLHttpRequest();
xmlhttp.open("post","tc.php?hidden8='.$current_user.'&ticketid='.$ticketnummer.'&ticketnummer='.$ticketno.'&hidden1=" + startdatum+"&hidden2=" + starttijd+"&hidden3=" + stopdatum+"&hidden4=" + stoptijd+"&hidden5=" + tekst+"&hidden6=" + stopdatumtijd + "&hidden7=" + checked , false);
xmlhttp.send();
}
thank you for the advice.
For some reason this script won't work. I'm using express, socket.io, jade and node.js.
Here is the script:
var socket = io.connect();
function addMessage(msg)
{
var currentDate = new Date();
var dateTime = currentDate.getDate() + "/" +
(currentDate.getMonth() + 1) + "/" +
currentDate.getFullYear() + "#"
currentDate.getHours() + ":" +
currentDate.getMinutes() + ":" +
currentDate.getSeconds();
$("#historyView").append("<p>" + dateTime + " - " + msg + "</p>");
}
function sentMessage()
{
if ($("#arduinoInput").val() != "")
{
socket.emit("message", $("#arduinoInput").val());
addMessage($('#arduinoInput').val(), new Date().toISOString(), true);
$("#arduinoInput").val("");
}
}
socket.on("message", function(message){
addMessage(message);
});
$document.ready(function(){
$("#submit").click(function(){
sentMessage();
});
});
It doesn't even clear the text box. Here is the jade page:
doctype 5
html
head
title Arduino Controller 2
script(src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js")
script(src="/socket.io/socket.io.js");
script(src="script.js")
link(rel="stylesheet" type="text/css" href="style.css")
body
div.container
header
h1 Arduino Controller 2
center
div#historyView
input(type="text")#arduinoInput
button#submit Send
I've been trying to debug this for awhile. I'm running this on Mac OS X 10.9 if that helps.
Assuming you don't have any other code, this would be incorrect:
$document.ready();
It is likely you meant to attach a ready handler to the document, which should look like this:
$(document).ready();
I'm trying to build a Node.js server with console logging similar to that of Django's development server. E.g.
[27/Jun/2011 15:26:50] "GET /?test=5 HTTP/1.1" 200 545
The following server.js (based on the Node Beginner Book tutorial) gets me the time and request information:
var http = require("http");
var url = require ("url");
var port = 1234;
function start(route, handle) {
function onRequest(request, response) {
var pathname = url.parse(request.url).pathname;
var query = url.parse(request.url).query;
route(handle, pathname, query, response);
logRequest(request);
}
http.createServer(onRequest).listen(port);
console.log("\nServer running at http://192.168.1.5:" + port + "/");
console.log("Press CONTROL-C to quit.\n");
}
function logRequest(request) {
var pathname = url.parse(request.url).pathname;
var query = url.parse(request.url).query;
if (query == undefined) {
query = "";
}
var currentDate = new Date();
var day = currentDate.getDate();
var month = currentDate.getMonth() + 1;
var year = currentDate.getFullYear();
var hours = currentDate.getHours();
var minutes = currentDate.getMinutes();
var seconds = currentDate.getSeconds();
if (minutes < 10) {
minutes = "0" + minutes;
}
if (seconds < 10) {
seconds = "0" + seconds;
}
console.log("[" + year + "/" + month + "/" + day +
" " + hours + ":" + minutes + ":" + seconds + '] "' +
request.method + " " + pathname + query +
" HTTP/" + request.httpVersion + '"');
}
exports.start = start;
Question: how would I update this code to get the response.statusCode and whatever the "545" number is into the log output?
When I tried adding the response object to the logRequest function, the response statusCode was always "200", even when I knew (via debug logging) that my router.js was generating 404 errors.
If you are using the route method found in the tutorial you linked, then the reason why using the response.statusCode doesn't work is because they set the 404 status code using this line
response.writeHead(404, {"Content-Type": "text/html"});
If you take a look at the documentation right there Node.JS Docs - writeHead it states that .writeHead will not set the .statusCode value. If you want to use the .statusCode value, you should change the line in the route method to read like this :
response.statusCode = 404;
response.setHeader("Content-Type", "text/html");
Directly assigning a value to statusCode and using "implicit" header declarations (setHeader instead of writeHead) will produce the same result for the user, but on your side you will have access to the statusCode later on in your log method.