Connecting Tech Pros Worldwide Help | Site Map

AJAX Not Working In Firefox

  #1  
Old July 18th, 2006, 03:55 AM
Danny R
Guest
 
Posts: n/a
I have the following javascript which works in either IE or Firefox but
not on both.

When I set the code to

http_request.open('POST', url, true) - Works in IE only
http_request.open('GET', url, true) - Works in Firefox only; Does not
refresh in IE.

How do I resolve this?

Thanks in advance.


=====================================

The page that uses AJAX is http://www.ubelt.com

http://www.ubelt.com/ub/apps/ajax/ajaxlatestphotos.js (for Full Code)

function makeHttpRequest(url, callback_function, return_xml)
{
var http_request = false;

if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
}

} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}

if (!http_request) {
alert('Unfortunatelly you browser doesn\'t support this
feature.');
return false;
}
http_request.onreadystatechange = function() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
if (return_xml) {
eval(callback_function +
'(http_request.responseXML)');
} else {
eval(callback_function +
'(http_request.responseText)');
}
} else {
//alert('There was a problem with the request.(Code: ' +
http_request.status + ')');
}
}
}
http_request.open('POST', url, true);
http_request.send(null);
}

  #2  
Old July 18th, 2006, 09:55 AM
Sjigger
Guest
 
Posts: n/a

re: AJAX Not Working In Firefox


Guestion why don't u use prototype? pretty easy and it work's in every
browser.

http://wiki.script.aculo.us/scriptac...show/Prototype

example:
new Ajax.Updater('mydiv', '/foo/bar', {method:'post',
postBody:'thisvar=true&thatvar=Howdy', asynchronous:true,
evalScripts:true});

evalScripts on the end means that when the ajax page you are calling
contains for example <script>alert('hello');</scriptit will execute
that the other stuff just echo't will be outputted to mydiv.

i give you this because i stoped using my own crap because this stuff
is alway's working

Hope this helps

Danny R wrote:
Quote:
I have the following javascript which works in either IE or Firefox but
not on both.
>
When I set the code to
>
http_request.open('POST', url, true) - Works in IE only
http_request.open('GET', url, true) - Works in Firefox only; Does not
refresh in IE.
>
How do I resolve this?
>
Thanks in advance.
>
>
=====================================
>
The page that uses AJAX is http://www.ubelt.com
>
http://www.ubelt.com/ub/apps/ajax/ajaxlatestphotos.js (for Full Code)
>
function makeHttpRequest(url, callback_function, return_xml)
{
var http_request = false;
>
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
}
>
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
>
if (!http_request) {
alert('Unfortunatelly you browser doesn\'t support this
feature.');
return false;
}
http_request.onreadystatechange = function() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
if (return_xml) {
eval(callback_function +
'(http_request.responseXML)');
} else {
eval(callback_function +
'(http_request.responseText)');
}
} else {
//alert('There was a problem with the request.(Code: ' +
http_request.status + ')');
}
}
}
http_request.open('POST', url, true);
http_request.send(null);
}
  #3  
Old July 18th, 2006, 09:55 AM
b83s
Guest
 
Posts: n/a

re: AJAX Not Working In Firefox


another thing...

stuff like this:
document.getElementById('ajax-latestphotos').innerHTML = html_content;

will become this:
$('ajax-latestphotos').innerHTML=html_content

  #4  
Old July 18th, 2006, 02:55 PM
Randy Webb
Guest
 
Posts: n/a

re: AJAX Not Working In Firefox


Sjigger said the following on 7/18/2006 4:57 AM:
Quote:
Guestion why don't u use prototype?
You should search the archives for articles about prototype.
Quote:
pretty easy and it work's in every browser.
No it doesn't.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
  #5  
Old July 18th, 2006, 03:55 PM
Danny R
Guest
 
Posts: n/a

re: AJAX Not Working In Firefox



Thanks for the response.

However, any of you guys know why this isn't working on both browsers?
Is there an alternative code that works on both?



Randy Webb wrote:
Quote:
Sjigger said the following on 7/18/2006 4:57 AM:
Quote:
Guestion why don't u use prototype?
>
You should search the archives for articles about prototype.
>
Quote:
pretty easy and it work's in every browser.
>
No it doesn't.
>
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
  #6  
Old July 19th, 2006, 03:25 PM
marss
Guest
 
Posts: n/a

re: AJAX Not Working In Firefox



Danny R написав:
Quote:
if (return_xml) {
eval(callback_function +
>'(http_request.responseXML)');
} else {
eval(callback_function +
>'(http_request.responseText)');
}
You can use http_request.responseXML only for appointed content type:

var respType = http_request.getResponseHeader("Content-Type");
if (respType == 'text/xml')
{
// process http_request.responseXML
}
else
{
// process http_request.responseText
}

Quote:
Does not refresh in IE.
It may be caused by caching.
Simple solution were posted here
http://groups.google.com.ua/group/co...33ea0f52689067

Instead of
var url = '/ub/apps/ajax/latestphotosxml.aspx';
use
var url = '/ub/apps/ajax/latestphotosxml.aspx?'+ Math.random();

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Request on another domain not working in firefox waqasahmed996 answers 2 December 5th, 2008 07:44 AM
request throught ajax on another server not working in firefox waqasahmed996 answers 1 December 5th, 2008 06:34 AM
Ajax is not working in firefox and opera benoypaul answers 8 September 30th, 2008 07:43 PM
AJAX not working in FireFox krishna.tunikipati@gmail.com answers 5 September 5th, 2008 12:25 PM