Solved

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

Posted on 2014-07-29
13
175 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 82

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
 
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 82

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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 82

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 108

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…

758 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

20 Experts available now in Live!

Get 1:1 Help Now