[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

XMLHttpRequest and Google Chrome

Rob@example.com

4/12/2015 6:36:00 PM



Chrome 41.0.2272.118
Windows 8.1

Chrome 41.0.2272.118
Ubuntu 12.10

Chrome 26.0.1410.43
Ubuntu 12.04 LTS

all 64bit

I'm having a problem with asynch' javascript requests in the above
versions of Chrome on the above platforms. The same code works fine in
various versions of Firefox and Opera on the above platforms.

The problem is worst on Ubu 12.10, not so bad but annoyingly frequent on
Win 8.1 and hardly happens at all on Ubu 12.04 LTS

Here's the admittedly old function I call to get an XMLHttpRequest object

function newXMLHttpRequest() {

var xmlreq = false;

if (window.XMLHttpRequest) {
// Create XMLHttpRequest object in non-Microsoft browsers
xmlreq = new XMLHttpRequest();

}
else if (window.ActiveXObject) {
try {
xmlreq = new ActiveXObject("MSXML2.XMLHTTP.3.0");
}
catch(e){
try {
// Try to create XMLHttpRequest in later versions
// of Internet Explorer
xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e1) {
// Failed to create required ActiveXObject
try {
// Try version supported by older versions
// of Internet Explorer
xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e2) {

// Unable to create an XMLHttpRequest with ActiveX
}
}
}
}
return xmlreq;
}

and here's a function I call when a page is loaded

function getCart(){
var req = newXMLHttpRequest();
req.onreadystatechange = getReadyStateHandler(req, updateCart);
req.open("POST", "common/ManageCart?cartmode=crtget", true);
req.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
req.send("");
}

updateCart uses javascript DOM to update the innerHTML property of a <div>

The error in the Chrome javascript console is

Uncaught TypeError: Cannot set property 'innerHTML' of null

Like I say, it's only Chrome that has this problem frequently enough to
be a problem

Any ideas on what might be causing this problem in Chrome greatly
appreciated

Thanks

Rob


--
Not floundering ... just fishing
30 Answers

RLunfa

8/4/2009 2:01:00 PM

0

Ac? el ?nico negro de mierda y calzonudo es Obama, quien se conforma con la
formalidad de Presidente para el negraje retardado y autista en general,
mientras la CIA hace lo que se le cantan los goivos.

Eso es lo que buscaban los rascatripas como Matt, Pinko, y otros
impresentables espec?menes.

A vos te gustar?a Cobos de Presidente?
Aaaaahhhh!!! Me imagino lo divertido de los primeros rounds con los perucas.
El COTI ya est? contando guita que todav?a no rob?, con la ayuda de qui?n?
Siiii !!! acertaste! de Manzano, el ex Ministro con nalgas de silicona!

No se vaya que viene lo mejor.

Besos,
RLunfa

"Dorothy" <vascaportania@yahoo.com.ar> escribi? en el mensaje
news:4a780ea4@news.x-privat.org...
> Boinas rojas recomienda el negro venezolano.
> Los radichetas usan boinas blancas. Y son mejor intencionados. Lo hicieron
> bien y los que
> sobornaron a los "Padres de la Patria" del 1900, les echaron a perder todo
> el puchero.
> Siempre se las arreglaron los radicha para parecer m?s decentes y
> honrados,
> con unos ejemplos de primera agua. Y no me lo van a quitar de la cabeza
> porque alguno se qued? con
> el az?car del caf?
>
> Besos
> Dorotea
> "RLunfa" <mitialagordasinestortoo@gmail.com> escribi? en el mensaje
> news:h57q8t$uvp$1@news.eternal-september.org...
>> Boinas rojas?
>>
>> Estos radichetas de mierda hacen quilombo en todos lados!
>>
>> A la horca con Cobos!
>>
>> RLunfa
>>
>> "Bufozzo" <educadito@gmail.com> escribi? en el mensaje
>> news:h57grq$kg0$1@news.eternal-september.org...
>> > Cona las boinitas rojas ,a la vista de todos ! ! !
>> > Faltaba que tuvieran puestas m?scaras de Ch?vez.
>> >
>> > JUAAAAAAAA ! ! ! ! ! ! !
>> >
>> > No olvidar de preguntarse: ?Quo bono?
>> >
>> > http://www.clarin.com/diario/2009/08/03/um/m-01...
>> >
>> >
>> > Sr Bufozzo
>> >
>>
>>
>
>


JJ

4/13/2015 5:33:00 AM

0

On Sun, 12 Apr 2015 19:36:08 +0100, Robbie Brown wrote:
>
> updateCart uses javascript DOM to update the innerHTML property of a <div>

Where? I don't see the code.

> The error in the Chrome javascript console is
>
> Uncaught TypeError: Cannot set property 'innerHTML' of null
>
> Like I say, it's only Chrome that has this problem frequently enough to
> be a problem

The problem is likely caused by whichever function that retrieve the DIV
element. Or the required ID or class attribute is missing in the DIV element
and/or its parent element.

Rob@example.com

4/13/2015 6:42:00 AM

0

On 13/04/15 06:33, JJ wrote:
> On Sun, 12 Apr 2015 19:36:08 +0100, Robbie Brown wrote:
>>
>> updateCart uses javascript DOM to update the innerHTML property of a <div>
>
> Where? I don't see the code.

Didn't show it

>> The error in the Chrome javascript console is
>>
>> Uncaught TypeError: Cannot set property 'innerHTML' of null
>>
>> Like I say, it's only Chrome that has this problem frequently enough to
>> be a problem
>
> The problem is likely caused by whichever function that retrieve the DIV
> element. Or the required ID or class attribute is missing in the DIV element
> and/or its parent element.

But it only happens intermittently, if there was a fundamental error in
the code it wouldn't work at all would it?


--
Not floundering ... just fishing

Martin Honnen

4/13/2015 9:30:00 AM

0

Robbie Brown wrote:

> and here's a function I call when a page is loaded
>
> function getCart(){
> var req = newXMLHttpRequest();
> req.onreadystatechange = getReadyStateHandler(req, updateCart);
> req.open("POST", "common/ManageCart?cartmode=crtget", true);
> req.setRequestHeader("Content-Type",
> "application/x-www-form-urlencoded");
> req.send("");
> }
>
> updateCart uses javascript DOM to update the innerHTML property of a <div>
>
> The error in the Chrome javascript console is
>
> Uncaught TypeError: Cannot set property 'innerHTML' of null

Please show the lines of code for which you get the error, the posted
code does not set any innerHTML. And we also need to see the
implementation of getReadyStateHandler.





--- news://freenews.netfront.net/ - complaints: news@netfront.net ---

Tim Streater

4/13/2015 12:18:00 PM

0

In article <mgg70i$19a$1@dont-email.me>, Robbie Brown <rob@example.com>
wrote:

>function updateCart(cartXML) {
> var cartsnapshot = document.getElementById("cartsnapshot");
> cartsnapshot.innerHTML = getCartSnapshot(cartXML);
>}

Where is the element cartsnapshot defined? Show us its html. ISTM that
there is no such element, in which case
document.getElementById("cartsnapshot") will return null. Or you are
running this javascript before the element is loaded.

--
"... you must remember that if you're trying to propagate a creed of
poverty, gentleness and tolerance, you need a very rich, powerful,
authoritarian organisation to do it." - Vice-Pope Eric

Rob@example.com

4/13/2015 12:35:00 PM

0

On 13/04/15 13:17, Tim Streater wrote:
> In article <mgg70i$19a$1@dont-email.me>, Robbie Brown <rob@example.com>
> wrote:
>
>> function updateCart(cartXML) {
>> var cartsnapshot = document.getElementById("cartsnapshot");
>> cartsnapshot.innerHTML = getCartSnapshot(cartXML);
>> }
>
> Where is the element cartsnapshot defined? Show us its html. ISTM that
> there is no such element, in which case
> document.getElementById("cartsnapshot") will return null. Or you are
> running this javascript before the element is loaded.
>

Jeez, It's like herding cats sometimes.

I have mentioned repeatedly that this code only causes problems in
Chrome, it works fine in other browsers

anyway, here's the html

<div id="rightcolumn" ondrop="dropOnList(event)"
ondragover="allowListDrop(event)">
<!-- cart -->
<div class="strbox">
<div class="top">
<img src="/static/cart.gif" alt='cart' title='cart'>&nbsp; Shopping Cart
</div>
<div class="middle">
<img src="/static/ukccheader.jpg" width='160' alt='Pay securely'
title='Pay securely'>
<div id="cartsnapshot">
<!-- if the cart doesn't appear here provide a button to allow a refresh -->
<div style="margin-top:7px; margin-bottom: 7px; overflow:hidden;
text-align:center">
<div style="font-size: 0.9em; font-weight:bold;">
Network congestion
</div>
<div style="margin-top: 7px;">
<input type='button' value="Refresh cart"
style="font-weight: bold;" onclick='getCart()'>
</div>
</div>
</div>
</div>
</div>

there is a common header that is included with every page

in the <head> of the common header I have this

<script type="text/javascript">
window.onload=getCart();
</script>

Once again, this is only a problem in some versions of Chrome.


--
Not floundering ... just fishing

Tim Streater

4/13/2015 1:26:00 PM

0

In article <mggd3o$n6r$1@dont-email.me>, Robbie Brown <rob@example.com>
wrote:

>On 13/04/15 13:17, Tim Streater wrote:
>> In article <mgg70i$19a$1@dont-email.me>, Robbie Brown <rob@example.com>
>> wrote:
>>
>>> function updateCart(cartXML) {
>>> var cartsnapshot = document.getElementById("cartsnapshot");
>>> cartsnapshot.innerHTML = getCartSnapshot(cartXML);
>>> }
>>
>> Where is the element cartsnapshot defined? Show us its html. ISTM that
>> there is no such element, in which case
>> document.getElementById("cartsnapshot") will return null. Or you are
>> running this javascript before the element is loaded.
>>
>
>Jeez, It's like herding cats sometimes.

Look, d'ye want help or not?

>I have mentioned repeatedly that this code only causes problems in
>Chrome, it works fine in other browsers

To me, that indicates that you're doing something in a non-guaranteed
way that just happens to work in those other browsers, but in Chrome
won't because Chrome happens to do things in a different order.

>there is a common header that is included with every page
>
>in the <head> of the common header I have this
>
><script type="text/javascript">
> window.onload=getCart();
></script>

Personally I tend to do:

<body onload="getCart();">

which works for me, doubtless others may have other preferences.

--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee

Martin Honnen

4/13/2015 2:16:00 PM

0

Robbie Brown wrote:

> <script type="text/javascript">
> window.onload=getCart();
> </script>

You should set

window.onload = getCart;

to have the function "getCart" called when the onload handler fires.
Your version calls "getCart" directly and assigns it result (which is
undefined) to the onload handler.


--- news://freenews.netfront.net/ - complaints: news@netfront.net ---

Ben Bacarisse

4/13/2015 2:50:00 PM

0

Robbie Brown <rob@example.com> writes:
<snip>
> there is a common header that is included with every page
>
> in the <head> of the common header I have this
>
> <script type="text/javascript">
> window.onload=getCart();
> </script>

This looks wrong. Did you mean 'window.onload=getCart'? The async HTTP
handler will run when there is no guarantee that the element it will
modify is present yet.

<snip>
--
Ben.

Rob@example.com

4/13/2015 3:04:00 PM

0

On 13/04/15 15:15, Martin Honnen wrote:
> Robbie Brown wrote:
>
>> <script type="text/javascript">
>> window.onload=getCart();
>> </script>
>
> You should set
>
> window.onload = getCart;
>
> to have the function "getCart" called when the onload handler fires.
> Your version calls "getCart" directly and assigns it result (which is
> undefined) to the onload handler.

Sorry, I don't understand, if I do as you say the function is never
called and the cart is never updated ...in fact this breaks the entire
ajax call in all browsers, can you elucidate, thanks.


--
Not floundering ... just fishing