Wrox Programmer Forums
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 30th, 2008, 03:19 PM
Registered User
 
Join Date: Jan 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need Code fix

Hi

I am trying to do compatibility between IE and Firefox. For the below Javascript it is working fine in the IE but I am not able to get the solution in the Firefox..

function ClientHTTPRequest(sRequestXML)
{
    var oXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
    var oError;
    // Put Tha System Wrapper Around
        sRequestXML = '<vinkit>' + sRequestXML;
        sRequestXML = sRequestXML + '</vinkit>';
    // Make A Call To The Server Page For The Request
        oXMLHttp.Open("POST","../VinKit-Common/RequestDB.aspx",false);

        oXMLHttp.Send(sRequestXML);
    // Now Return The Result DOM

        return oXMLHttp.responseXML;



}

If anyone has done this crss browser comptability can you provide with a solution.

Thanks in advance

Hema

 
Old January 30th, 2008, 05:15 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

You have to do a test like this:

var oXMLHttp;
if(window.XMLHttpRequest)
{
   //Mozilla
   oXMLHttp = new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
    oXMLHttp = new ActiveXObject("Msxml2.XMLHTTP");
}

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old January 31st, 2008, 05:10 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I suggest you get zXml from Nicholas C. Zakas' site. Then either use the library directly or examine how the code their creates a cross-broswer XMLHttpRequest wrapper. Search for zXmlHttp.createRequest.

--

Joe (Microsoft MVP - XML)
 
Old January 31st, 2008, 12:21 PM
Registered User
 
Join Date: Jan 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for both of you I really appreciate your time on this.

I changed my script as below , but still I get /* oXMLHttp.Open is not a function*/ error when I try to open the page.

function ClientHTTPRequest(sRequestXML)
{
var oError;

if (window.XMLHttpRequest)
{
var oXMLHttp =new XMLHttpRequest();
oXMLHttp.Open("GET","sRequestXML",true);
oXMLHttp.onreadystatechange = function ()
{
if (oXMLHttp.readyState == 4 && oXMLHttp.status == 200)
{if (oXMLHttp.responseXML == null) {
            // Failed; didn't load data into DOM object
            return;
                            }
        // Success
        oXMLHttp.responseXML;

 }

else if (window.ActiveXObject)
{ var aVersions = [ "Microsoft.XMLHTTP"];
   for (var i = 0; i < aVersions.length; i++)
     {
          try {
                var oXMLHttp = new ActiveXObject(aVersions[i]);
                   // Put Tha System Wrapper Around
            sRequestXML = '<vinkit>' + sRequestXML;
            sRequestXML = sRequestXML + '</vinkit>';
        // Make A Call To The Server Page For The Request
            oXMLHttp.Open("POST","../VinKit-Common/RequestDB.aspx",false);
            oXMLHttp.Send(sRequestXML);
        // Now Return The Result DOM
        return oXMLHttp.responseXML;
                  }
     catch (oError)
     {
                //Do nothing
                   }
             }
  }
}

I am not sure of the error because this is the page I awant to access during the request.. Is there anything I should not pass the aspx page??

Please let me know.. Thanks in advance..

 
Old January 31st, 2008, 04:03 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

There must be something you're not showing, opening the page doesn't even start the ClientHTTPRequest function. Which line is flagged as the error?

--

Joe (Microsoft MVP - XML)
 
Old January 31st, 2008, 04:41 PM
Registered User
 
Join Date: Jan 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey Joe

Actually I am updating our application to Mozilla so in my appllication when I try to open a page which consists this jscript code I AM GETTING THE ERROR.

The error throws at the line

oXMLHttp.Open is not a function
oXMLHttp.Open("GET",url,true);
Thanks again!






Similar Threads
Thread Thread Starter Forum Replies Last Post
please fix this function keyvanjan ASP.NET 2.0 Professional 4 September 18th, 2007 08:01 AM
HOW TO -REG DYNAMIC DROPDOWN BOX.(FIX MY CODE) kaniths Javascript How-To 2 December 21st, 2006 08:44 PM
New Chapter 3 Fix .MAttButler BOOK: Professional Web Parts and Custom Controls ASP.NET ISBN: 0-7645-7860-X 0 August 14th, 2006 09:08 PM
Help! How do I fix this? missusfinz Crystal Reports 1 April 1st, 2005 12:27 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.