Solved

javascript code - new ActiveXObject("Microsoft.XMLHTTP")

Posted on 2014-07-29
13
197 Views
Last Modified: 2015-04-30
I have an old website, it has a cold-fusion file - myfirstpage.cfm with this javascript-  code  -
<script>
function myfunct()
{
 var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 xmlhttp.open("GET","http://"+document.location.host+"/Mysecondpage.cfm",false);
 xmlhttp.send();
   
  var strResponse = xmlhttp.ResponseText;
 }
</script>
   
The website is not working after user got new browser - IE 11, so i am trying to find how to fix the website
I feel the problem is with the code above, does the code written above has any issues with new browsers?

Please help & guide

thanks  so much
0
Comment
Question by:ts84zs
  • 4
  • 3
  • 3
  • +1
13 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40227838
ActiveX is disabled in IE10+ and that code is pre IE7 - you should be using

var xmlhttp = new XMLHttpRequest();
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40227840
That's old code and I believe that ActiveX doesn't work in IE11.  Here's a link to more modern code from the W3Schools tutorial: http://www.w3schools.com/ajax/ajax_xmlhttprequest_create.asp
0
 

Author Comment

by:ts84zs
ID: 40227864
Do i have to import any javascript - js files to make that code you advised to work like
for e.g. -
<script src="http://aaa.bbbcom/cc/libs/ddd/somejavascriptcode.js"
            ></script>
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 58

Assisted Solution

by:Gary
Gary earned 500 total points
ID: 40227875
No, everything else is the same it's just the way you initiate the object that has changed
http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp

For an easier way you may want to look at jQuery which simplifies js including ajax calls
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40227880
The AJAX tutorial that Gary and I have both given you a link to covers it all.  You don't need any external files for the AJAX part of it.  You just need to update your code.
0
 

Author Comment

by:ts84zs
ID: 40227884
ok thanks a lot let me try that
0
 

Author Comment

by:ts84zs
ID: 40227887
The problem with the old code was that it was running that javascript code for the 1st time when the page is loaded
Next time it does not run that javascript code, but if i delete history and close the browser and reopen the page then that code works .... ...
code:

<script>
function myfunct()
{
 var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 xmlhttp.open("GET","http://"+document.location.host+"/Mysecondpage.cfm",false);
 xmlhttp.send();
   
  var strResponse = xmlhttp.ResponseText;
 }
</script>


any ideas why? thanks so much
0
 
LVL 58

Expert Comment

by:Gary
ID: 40227895
Confused - what is supposed to be happening?
How is your myfunct() called?
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40227987
Sometimes the browser will 'cache' the AJAX content.  The way around that is to add a random number or timestamp as a query string so the complete URL will never be the same twice.
<script>
function myfunct()
{
 var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
murl="?qdat="+mstr+Math.random();
xmlhttp.open("GET","http://"+document.location.host+"/Mysecondpage.cfm"+murl,false);
xmlhttp.send();
   
  var strResponse = xmlhttp.ResponseText;
 }
</script> 

Open in new window

Shown on this page: http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 40228101
+1 for the recommendation of jQuery.  This article shows the "hello world" example of jQuery/AJAX.  jQuery is a good cross-browser library that implements the good parts of JavaScript.
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Jquery/A_10712-The-Hello-World-Exercise-with-jQuery-and-PHP.html
0
 

Author Comment

by:ts84zs
ID: 40239113
thanks all i am looking into it...
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now