I am trying to follow the this tutorial ( http://www.codeproject.com/KB/webservices/CallWebServiceFromHtml.aspx ) and learn to call a web service from a web page. However, I´m getting an error in the Firebug console:
service is not defined
InitializeService() onload() event =
load
service.useService("http://tm.a...smx?WSDL",
"TryggMedisinWebService");
This is the relevant code I´m using.
<script language="JavaScript">
function InitializeService() {
service.useService("http://tm.arnett.no/tryggmedisinwebservice/tryggmedisinwebservice.asmx?WSDL", "TryggMedisinWebService");
}
var spm, kategori, fylke;
function SendQuestion(){
spm = document.send_question.spm.value;
kategori = document.send_question.kategori.value;
fylke = document.send_question.fylke.value;
service.TryggMedisinWebService.callService("Send_Question", spm, kategori, fylke);
}
function ShowResult(){
alert(event.result.value);
}
</script>
<body onload="InitializeService()" id="service" style="behavior:url(<?php bloginfo('template_directory'); ?>/webservice.htc)" onresult="ShowResult()" <?php body_class(); ?>>
I would appreciate any help i can get on troubleshooting this.
Thanks!
This is using .htc file and as far as I know it's supported only by IE browsers.
To have it work in other browsers, switch to using ordinary AJAX - for example jQuery provides excellent interface.
Here is link to good article explaining how to consume web service using jQuery:
http://www.c-sharpcorner.com/UploadFile/sridhar_subra/116/
Didn't personally test it, but from what I've seen the information there is accurate and to the point.
Related
I try to run a simple ETL process on a schedule to populate a SQL Server database table on a .Net shared hosting. The EXE file will be hosted with the website and when it runs it will make some API calls and get data to update the website's SQL table.
My hosting company allows such thing (to call an exe file on schedule) with an extra fee, but they require me to have it wrapped and be called using URL. They don't mind any technology to use as long as I provide a URL. I did few attempt to get this setup working with no luck. For example I tried two ways below: Note, I just started to learn JavaScript, I use C# but this is my first time attempt to do something like that and I might be completely off. Any help will be appreciated.
<html>
<head>
<title>Open PMETL</title>
<script type="text/javascript">
function runProgram()
{
try {
var shell = new ActiveXObject("WScript.Shell");
var myPMETL="http://trudat.live/RefreshData.exe";
shell.Run(myPMETL);
}
catch (e) {
alert(e.message);
}
}
function runProgram02() {
if (window.ActiveXObject) {
try {
var excelApp = new ActiveXObject ("Excel.Application");
excelApp.Visible = true;
}
catch (e) {
alert (e.message);
}
}
else {
alert ("Your browser does not support this example.");
}
}
</script>
</head>
<body>
Run program
Run program02
</body>
</html>
I was able to achieve that by adding a new page to my ASP.NET application and port the console application into the code-behind C# and invoke the code through the Page_Load() method. This allowed my to give the hosting company a URL like http://mydomain/ExePage.aspx without impacting my original application since this new page is not reachable from the application's menu. it was a convenient way to give me what I needed.
I assume this is not a typical solution since I had the advantage to have the source code of the EXE program, but nevertheless it is a very effective, and this might help someone in the future.
I'm trying to create a burndown chart on a webapp and using the loginkey example code, but switched loginkey to apikey (code below). My API Key is placed where it says CorrectAPIKeyHere, and actual id's for workspace_id and project_id. I have double checked to make sure it's the correct key. Here's what shows up: http://pasteboard.co/P3WXWgPk.png
However, the code works if I'm already logged into Rally. Is there anything I'm missing from my code?
<script type="text/javascript" src="https://rally1.rallydev.com/apps/1.26/sdk.js?apiKey=CorrectAPIKeyHere"></script>
<script type="text/javascript" src="https://rally1.rallydev.com/apps/1.26/sdk.js"></script>
<script type="text/javascript">
function initPage() {
console.log(gon.project_oid);
var rallyDataSource = new rally.sdk.data.RallyDataSource("workspace_id", project_id,"true","false");
console.log($(main_content).width());
var config = {
report: rally.sdk.ui.StandardReport.IterationBurndown,
height: 400,
iterations: iteration_id
};
var report = new rally.sdk.ui.StandardReport(config);
report.display("burndown_chart");
}
rally.addOnLoad(initPage);
</script>
Unfortunately there are a couple different things contributing to your current bad times. API Keys are not supported in App SDK 1.x. They are also not supported by the Analytics1 service which backs that StandardReport component.
So the only way forward is to go back to using LoginKey, which comes with the usual caveats about security, etc. Did you have a working app with LoginKey?
Good news! Api Keys are fully supported now in App SDK 2.1 and the StandardReport component so it should be totally possible to do this now.
Some useful links:
Embedding apps externally:
https://help.rallydev.com/apps/2.1/doc/#!/guide/embedding_apps
The StandardReport component:
https://help.rallydev.com/apps/2.1/doc/#!/api/Rally.ui.report.StandardReport
I'm trying to get websockets working with ColdFusion. I am unable to send or receive messages and I am at a loss as to why. Am I missing something? Do I need to have any other programs installed? I am using Adobe ColdFusion Builder 3 Developer Edition.
Here is the code I am attempting to use.
Websocket.cfm
<cfwebsocket name="mycfwebsocketobject" onmessage="MessageHandler" subscribeto="stocks" >
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
function MessageHandler(message)
{
alert(message.data);
}
function publishstock()
{
mycfwebsocketobject.Publish('stocks', 'I sent a message!');
}
setInterval('publishstock()',1000);
</script>
Application.cfc
<cfcomponent>
<cfset this.name="Websocket">
<cfset this.wschannels=[{name="stocks"}]>
</cfcomponent>
My goal is to get the MessageHandler function to trigger without explicitly calling it. I have no idea what is wrong and I have matched my code up perfectly with many examples on the web. I have been unsuccessful in both Chrome and Firefox.
I think that the real problem might have something to do with my machine. I found a demo online that worked perfectly, but when I downloaded the source it no longer worked. Is there a way to test for this?
Resources:
https://www.youtube.com/watch?v=Ys6BGrYJhNg
http://www.adobe.com/devnet/coldfusion/articles/html5-websockets-coldfusion-pt1.html
Your setInterval('publishstock()',1000);
Should be:
setInterval(function(){publishstock();},1000);
There was an IE-10 security update on Sept-10. After that, in my application there seems to be an issue accessing a standard div using jquery.
Here is the quick scenario :
I have a jsp layout template where there is a div defined :
<div id="abc"></div>
In that I include a js file k1.js, the following function in that is triggered upon a click of a button
function sample() {
jQuery.get("/fetchmedata.do?a=true", function(data) {
jQuery("#abc").html(data);
});
This was totally functioning across all browsers including ie-10 till Sept -10. After 10th, it still works fine on IE-9 and old IE-10 builds, but on new IE-10 build throws the error in console :
SCRIPT5 : Access is denied
The call stack pointed to internals of Jquery code which I couldn't decipher/understand the context.
The quick fix was to replace the jquery with Javascript, and it worked :
function sample() {
jQuery.get("/fetchmedata.do?a=true", function(data) {
document.getElementById('abc').innerHTML = data;
});
The jquery version was jquery-1.4.4.min.js.
Please advice on what could have been the issue, is it again probably related to not using XDomainRequest instead of XHR, so that we could take precautions in the code to avoid future issues.
Also what is the best practices around it ?
Please advice.
I have a JsFiddle here, and added Microsoft AJAX to be loaded through external JS/resource section. How can I tell whether or not my JS code is run after the AJAX file has finished loading?
Seems that the AJAX does not load either. :(
Here is the code in the JSFiddle:
Type.registerNamespace("Tutorial.Chapter1");
Tutorial.Chapter1.Person = function(firstName, lastName) {
this._firstName = firstName;
this._lastName = lastName;
};
Tutorial.Chapter1.Person.prototype = {
set_firstName: function(value) {
this._firstName = value;
},
get_firstName: function() {
return this._firstName;
},
set_lastName: function(value) {
this._lastName = value;
},
get_lastName: function() {
return this._lastName;
},
_firstName: "",
_lastName: "",
displayName: function() {
alert("Hi! " + this._firstName + " " + this._lastName);
}
};
Tutorial.Chapter1.Person.registerClass("Tutorial.Chapter1.Person", null);
The External Resources tab of jsFiddle is currently somewhat tricky and unstable to use.
The resources defined here are often not correctly included into the code. There seems to be an issue with the automatic recognition of JS and CSS resources. If this happens, the external resource is simply not added to the head section of the resulting code. You can check that by reviewing the source code of the Result frame of your jsFiddle. You will find that your MS AJAX resource is simply NOT mentioned in the resulting HTML code.
The correct recognition can actually be forced by adding a dummy value to the resource's URL like this (see –>jsFiddle docs for more info):
...&dummy=.js
Here is an example that shows how to add the external Google Maps API resource to a jsFiddle (mind the dummy parameter at the very end!):
https://maps.googleapis.com/maps/api/js?sensor=false&dummy=.js
Unfortunately this won't work for you as the MS AJAX URL will fail when additional parameters are appended.
A solution (and currently the safest way to load external resources) is to avoid the External Resources tab altogether and load external code manually in the first line(s) of jsFiddle's HTML window like this:
<script type='text/javascript' src="http://ajax.aspnetcdn.com/ajax/3.5/MicrosoftAjax.js"></script>
Here is your jsFiddle modified to use that method: http://jsfiddle.net/rEzW5/12/
It actually does not do a lot (I did not check what is wrong with the rest of your code), but at least it does not throw JavaScript errors anymore.
Open "Add Resources" section and add the url of your external script...
#Jpsy's approach no longer seems to work (see my comment under his answer).
For me, adding the resource under External Resources also didn't work. (According to the Firefox Debugger, it couldn't find the resource).
The only way I was able to get an external bit of JavaScript code (in my case jquery.backstretch.js) to work, was to use Google to find a Fiddle which used this resource (and worked), then Fork this Fiddle and copy/paste all my code into the HTML, CSS and JavaScript panels. Ugh!
#clayRay, You absolutely went thru a code surgery. Just resolved that by mentioning external source in plain html which in my case is
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
Using External Resources tab didn't help a bit...