Solution for Use of Webservices in Firefox using Javascript
-
This code has been checked in IE6, IE7 and Firefox and it works perfectly in all of them. Here is the Javascript code which you need to put within <script> tag. var req; var isIE; function initRequest() { if (window.XMLHttpRequest) { req = new XMLHttpRequest(); } else if (window.ActiveXObject) { isIE = true; req = new ActiveXObject("Microsoft.XMLHTTP"); } } //url will be Web Service URL. function CallWebService(url,params) { initRequest(); req.onreadystatechange = processRequest; req.open("POST", url, true); if(params!=null)req.setRequestHeader("Content-length", params.length); req.setRequestHeader("Connection", "close"); req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); req.send(params); } function processRequest() { if (req.readyState == 4) { if (req.status == 200) { var message = req.responseXML; //Result in XML. // Accessing the tag 'string' is name of node var myNodes=message.getElementsByTagName("string"); // Getting actual result of webservice and saving it in a variable which can be use anywhere in page. // alert("Result of webservice is : "+myNodes.item(0).firstChild.nodeValue);// Checking result var serviceValue=myNodes.item(0).firstChild.nodeValue; } } } Here is the Html code which you can put within <body> tag. <%--<input type="button" value="Call .NET Web Service!" onclick="CallWebService('http://pathOfYourServer/nameOfWebService.asmx/testWebService1',null)" /> <input type="button" value="Call .NET Web Service with parameters!" onclick="CallWebService('http://pathOfYourServer/nameOfWebService.asmx/testWebService2','a=Michael&b=5')" /> You can also pass dynamic values like below CallWebService("http://pathOfYourServer/nameOfWebService.asmx/testWebService2","name1="+value1+"&name2="+value2+"&name3="+value3+"") where name(1,2,3) is the name of your variable and value(1,2,3) is value of respective variable. Note: Number of variables you pass in above line must be same as you defined in the definition of webservice. Here is the webservice code which you need to enter in your webservice file. using System; using System.Web; using System.Collections; using System.Web.Services; using System.Web.Services.Protocols; /// /// Summary description for WebService /// [WebService(Namespace = "http://tempuri.org/")] [
-
This code has been checked in IE6, IE7 and Firefox and it works perfectly in all of them. Here is the Javascript code which you need to put within <script> tag. var req; var isIE; function initRequest() { if (window.XMLHttpRequest) { req = new XMLHttpRequest(); } else if (window.ActiveXObject) { isIE = true; req = new ActiveXObject("Microsoft.XMLHTTP"); } } //url will be Web Service URL. function CallWebService(url,params) { initRequest(); req.onreadystatechange = processRequest; req.open("POST", url, true); if(params!=null)req.setRequestHeader("Content-length", params.length); req.setRequestHeader("Connection", "close"); req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); req.send(params); } function processRequest() { if (req.readyState == 4) { if (req.status == 200) { var message = req.responseXML; //Result in XML. // Accessing the tag 'string' is name of node var myNodes=message.getElementsByTagName("string"); // Getting actual result of webservice and saving it in a variable which can be use anywhere in page. // alert("Result of webservice is : "+myNodes.item(0).firstChild.nodeValue);// Checking result var serviceValue=myNodes.item(0).firstChild.nodeValue; } } } Here is the Html code which you can put within <body> tag. <%--<input type="button" value="Call .NET Web Service!" onclick="CallWebService('http://pathOfYourServer/nameOfWebService.asmx/testWebService1',null)" /> <input type="button" value="Call .NET Web Service with parameters!" onclick="CallWebService('http://pathOfYourServer/nameOfWebService.asmx/testWebService2','a=Michael&b=5')" /> You can also pass dynamic values like below CallWebService("http://pathOfYourServer/nameOfWebService.asmx/testWebService2","name1="+value1+"&name2="+value2+"&name3="+value3+"") where name(1,2,3) is the name of your variable and value(1,2,3) is value of respective variable. Note: Number of variables you pass in above line must be same as you defined in the definition of webservice. Here is the webservice code which you need to enter in your webservice file. using System; using System.Web; using System.Collections; using System.Web.Services; using System.Web.Services.Protocols; /// /// Summary description for WebService /// [WebService(Namespace = "http://tempuri.org/")] [
Cool..... :) I glad to hear that your problem is solved.... As I suggest you earlier, if you are working for large Ajax-enabled project, you may probably want to use Javascript Ajax framework (eg: prototype js library) or ASP.NET Ajax...
Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)
-
Cool..... :) I glad to hear that your problem is solved.... As I suggest you earlier, if you are working for large Ajax-enabled project, you may probably want to use Javascript Ajax framework (eg: prototype js library) or ASP.NET Ajax...
Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)
I already voted your message. I posted a new message in forumn, may be you already read it if u didn't I am repeating here again. if you know its answer please reply its answer. Thanks. QUESTION I want to use embedded Window Media Player functions like stop(), pause() in Firefox. Does anyone have an idea? I checked following two ways. They are working good in IE6 and IE7 but not in Firefox. (1) document.Player.controls.pause(); (2) document.getElementById("Player").controls.pause(); Please tell me a solution in Firefox. Thanks. Abuabakr
-
I already voted your message. I posted a new message in forumn, may be you already read it if u didn't I am repeating here again. if you know its answer please reply its answer. Thanks. QUESTION I want to use embedded Window Media Player functions like stop(), pause() in Firefox. Does anyone have an idea? I checked following two ways. They are working good in IE6 and IE7 but not in Firefox. (1) document.Player.controls.pause(); (2) document.getElementById("Player").controls.pause(); Please tell me a solution in Firefox. Thanks. Abuabakr
Why do you wanna add this from Javascript? If you are embedding Windows Media Player Object in WebPage, all buttons (play,pause,stop and etc) are already included in that object. So, I don't think you need to add this duplicated features from Javascript.. You can check the screenshot here.
<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" name="mediaplayer1" ShowStatusBar="true" EnableContextMenu="false" autostart="false" width="320" height="240" loop="false" src="MyVideo.wmv" />
Ref: Embedding Windows Media Player into a web page
Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)