473,324 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Ajax Problem

ste
Hi, I used the code below for a function that I have to repeat with the same
code. Samething like the stars in gmail for example that with one click I
sign a message, with the second I sign-off the message.
My code work perfect with Firefox but with Mozilla it work only the first
time that I click the command. I hope my question clear. Sorry for bad
English and thanks for your answers. Stefano.

Ho usato il codiceseguente che sotto mozilla funziona bene, sotto IE mi
funziona solo la prima volta, dalla seconda in poi mi ripete la stessa
cosa...cosa devo cambiare?grazie.

var http_request = false;

function makeRequest(url) {

if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
http_request.onreadystatechange = alertContents;
http_request.open('GET', url, true);
http_request.send(null);

}

function alertContents() {

if (http_request.readyState == 4) {
if (http_request.status == 200) {
alert(http_request.responseText);
} else {
alert('There was a problem with the request.');
}
}

}

Feb 27 '06 #1
8 1270
ste wrote:
[...]
My code work perfect with Firefox but with Mozilla it work only the first
time that I click the command.
[...]
var http_request = false;

function makeRequest(url) {

if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
http_request.onreadystatechange = alertContents;
http_request.open('GET', url, true);


open() resets all event listeners. Switch the order of the last two
statements.

<URL:http://xulplanet.com/references/objref/XMLHttpRequest.html#method_open>
HTH

PointedEars
Feb 27 '06 #2
ste
"Thomas 'PointedEars' Lahn" <Po*********@web.de> wrote in message
news:13****************@PointedEars.de...
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
http_request.onreadystatechange = alertContents;
http_request.open('GET', url, true);


open() resets all event listeners. Switch the order of the last two
statements.


Sorry but I have the same problem...
Feb 27 '06 #3
VK

ste wrote:
Hi, I used the code below for a function that I have to repeat with the same
code. Samething like the stars in gmail for example that with one click I
sign a message, with the second I sign-off the message.
My code work perfect with Firefox but with Mozilla it work only the first
time that I click the command. I hope my question clear. Sorry for bad
English and thanks for your answers. Stefano.

Ho usato il codiceseguente che sotto mozilla funziona bene, sotto IE mi
funziona solo la prima volta, dalla seconda in poi mi ripete la stessa
cosa...cosa devo cambiare?grazie.


Sorry, but your English version was misleading. The googled Italian one
says:
"under IE me works only before the time, from the second one in then me
repeats the same thing"

Now it's clear: you need either disable caching by setting response
header or you need to randomize your URL.

Quick'n'dirty (presuming your URL already contains some search part
like ...?foo=bar):

// this line is added:
url+= '&rnd=' + (new Date()).getTime();

http_request.open('GET', url, true);

Feb 27 '06 #4
ste
"VK" <sc**********@yahoo.com> wrote in message
news:11*********************@i39g2000cwa.googlegro ups.com...
Now it's clear: you need either disable caching by setting response
header or you need to randomize your URL.

Quick'n'dirty (presuming your URL already contains some search part
like ...?foo=bar):

// this line is added:
url+= '&rnd=' + (new Date()).getTime();

http_request.open('GET', url, true);


I solved my problem changing GET with POST!
Feb 27 '06 #5
ste wrote:

[Restored attribution]
"Thomas 'PointedEars' Lahn" [...] wrote [...]
ste wrote:
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
http_request.onreadystatechange = alertContents;
http_request.open('GET', url, true);


open() resets all event listeners. Switch the order of the last two
statements.


Sorry but I have the same problem...


Since you did not post how this code is called, one can only make an
educated guess, if that. Maybe you are using some `href="javascript:'
code. See the FAQ about it:

<URL:http://jibbering.com/faq/>

Please do not remove previous attribution lines when quoting.
PointedEars
Feb 28 '06 #6
ste wrote:
"VK" [...] wrote [...]:
Now it's clear: you need either disable caching by setting response
header or you need to randomize your URL.

Quick'n'dirty (presuming your URL already contains some search part
like ...?foo=bar):

// this line is added:
url+= '&rnd=' + (new Date()).getTime();

http_request.open('GET', url, true);


I solved my problem changing GET with POST!


It only works now (if it really works) because POST requests are not cached
in _your_ environment. Using some kind of cache control as suggested (where
the above suggestion is not the best approach to this) is the reasonable
course of action.
PointedEars
Feb 28 '06 #7
ste
"Thomas 'PointedEars' Lahn" <Po*********@web.de> wrote in message
news:26****************@PointedEars.de...
ste wrote:

[Restored attribution]
"Thomas 'PointedEars' Lahn" [...] wrote [...]
ste wrote:
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
http_request.onreadystatechange = alertContents;
http_request.open('GET', url, true);

open() resets all event listeners. Switch the order of the last two
statements.


Sorry but I have the same problem...


Since you did not post how this code is called, one can only make an
educated guess, if that. Maybe you are using some `href="javascript:'
code. See the FAQ about it:

I called the code with:

echo "<a href=\"#\"
onclick=\"makeRequest('tick.php?tick=prima&id=$res ult[id]')\"><img
src=\"img/tick.gif\" border=\"0\" alt=\"Add\"></a>";

with php sintax.
Feb 28 '06 #8
ste wrote:
echo "<a href=\"#\"
onclick=\"makeRequest('tick.php?tick=prima&id=$res ult[id]')\"><img
src=\"img/tick.gif\" border=\"0\" alt=\"Add\"></a>";
with php sintax.


When posting to a javascript newsgroup, it's best to post the souce of the
page after it has been delivered to the browser.
Your code above surely results in this:

<a href="#" onclick="makeRequest('tick.php?tick=prima&id=$resu lt[id]')"><img
src="img/tick.gif" border="0" alt="Add"></a>

which would explain the problem. There is no 'return false' in your onClick
handler, so the browser then goes to your href="#".
See http://www.JavascriptToolbox.com/bestpractices/ for information about
correctly triggering javascript actions from anchor tags.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Feb 28 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: bobzimuta | last post by:
I'm creating a simple AJAX library. It's an object that will return an array containing the response text or xml. I'm trying to find a way to assign the response as a property of the object, but...
31
by: Tony | last post by:
I just noticed that prototype.js is one of the files in the Ajax.NET distribution - I'm pretty concerned about this. Does anyone know if this is the same "prototype.js" that is not well-liked...
5
by: Martin | last post by:
Hello NG, I've been doing some AJAX for a few weeks now. The basics worked fine so far, but now I've got the following problem which I can't solve: With AJAX you typically update/replace only...
3
by: Alok yadav | last post by:
I have an open IP and on that IP our main application is hosted. it uses ajax. in web.config file i have register ajax handlers. there are also other sites or project on that IP. now my problem is...
3
by: equazcion | last post by:
Hi, I have an image reference (IMG) in my page that changes depending on the value of a database field. Clicking the image triggers an Ajax call to change the database field (toggles the field...
7
by: tommurray | last post by:
Hi all Hope someone can help with the problem I am having as it is driving me nuts! I have the below script on my site the problem lies with passing through a url parameter in the below line...
6
by: =?Utf-8?B?U2hhd24gU2VzbmE=?= | last post by:
Greetings! I was researching AJAX to provide a solution to displaying status messages while a long process executed. I found several examples online and was able to use their code to get a quick...
2
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
3
by: willl69 | last post by:
Hi All, Ive been having a problem of late with one of my sites that uses PHP5 / Ajax. The problem is that periodically the ajax functions lock up and it gets stuck in the loading phase of the...
2
by: majidtou | last post by:
Hi , We have an HTML page which is using AJAX. We make an AJAX call which retrieves a table with mutiple rows. We need to extend this functionality. In the table, we want to put a button on each...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.