Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

AJAX problem in Internet Explorer

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,
I am trying to build a very simple code for AJAX
When i run the code...I get error as "out of memory at line 33" in Internet Explorer 6
the java scripts code is

------------------

var request;

function getRequestObject() {

if (window.ActiveXObject) {

return(new ActiveXObject("Microsoft.XMLHTTP"));
} else if (window.XMLHttpRequest) {

return(new XMLHttpRequest());
} else {
return(null);
}
}

function sendRequest(address) {
request = getRequestObject();
request.onreadystatechange = showResponseAlert;(line 33)
request.open("GET", address, true);
request.send(null);
}

function showResponseAlert() {
if ((request.readyState == 4) &&
(request.status == 200)) {
alert(request.responseText);
}
}

function sendRequestWithData(address, data, responseHandler) {
request = getRequestObject();
request.onreadystatechange = responseHandler;
request.open("POST", address, true);
request.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
request.send(data);

displayTimeInCity();

}

function showTimeInCity() {
var address = "../ShowTimeInCity";
var city = document.getElementById("city").value;
var data = "city=" + escape(city);
sendRequestWithData(address, data, showResponseAlert);
}

function displayTimeInCity() {

var address = "../ShowTimeInCity";
var city = document.getElementById("city").value;
var data = "city=" + escape(city) + "&useHTML=true";
sendRequestWithData(address, data, showResponseText);
}

function showResponseText() {
if ((request.readyState == 4) &&
(request.status == 200)) {
document.getElementById("resultText").innerHTML =
request.responseText;
displayTimeInCity();
}
}


----------------
please help me how to resolve

 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well there is a lot of issues with the code, ActiveX should be checked after the native object since IE7 suppors both. Better to use native than ActiveX.

Open should come before onreadystatechange since there is a bug in IE

But the real problem is: You have an infinite loop happening. Walk through the code and you will see that you kep calling the displayTimeInCity();, that should not be in the call, it should be in the final check.

To make your life easier you whould look into JQuery or Prototype.js and use their Ajax implementation.

Eric
 
Rohan Kalbhor
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Eric,
thanks for the guidance
I have used the infinite loop to update the field continuously.
any solution for that,without flooding the IE memory...
something like fluash memory
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should call it after you get the response back to the server.

If this is for a production application, you are going to kill that box.

Eric
 
Rohan Kalbhor
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey Eric its just an example..

i discovered that if Model view architecture is used in AJAX application.This problem is washed away


cheers
Rohan
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic