AJAX Not Working In Firefox

Discussion in 'Javascript' started by Danny R, Jul 18, 2006.

  1. Danny R

    Danny R Guest

    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);
    }
    Danny R, Jul 18, 2006
    #1
    1. Advertising

  2. Danny R

    Sjigger Guest

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

    http://wiki.script.aculo.us/scriptaculous/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');</script> it 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:
    > 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);
    > }
    Sjigger, Jul 18, 2006
    #2
    1. Advertising

  3. Danny R

    b83s Guest

    another thing...

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

    will become this:
    $('ajax-latestphotos').innerHTML=html_content
    b83s, Jul 18, 2006
    #3
  4. Danny R

    Randy Webb Guest

    Randy Webb, Jul 18, 2006
    #4
  5. Danny R

    Danny R Guest

    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:
    > Sjigger said the following on 7/18/2006 4:57 AM:
    > > Guestion why don't u use prototype?

    >
    > You should search the archives for articles about prototype.
    >
    > > 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/
    Danny R, Jul 18, 2006
    #5
  6. Danny R

    marss Guest

    Danny R напиÑав:

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


    > Does not refresh in IE.


    It may be caused by caching.
    Simple solution were posted here
    http://groups.google.com.ua/group/c...5568313f853/7833ea0f52689067#7833ea0f52689067

    Instead of
    var url = '/ub/apps/ajax/latestphotosxml.aspx';
    use
    var url = '/ub/apps/ajax/latestphotosxml.aspx?'+ Math.random();
    marss, Jul 19, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. minnie
    Replies:
    1
    Views:
    684
    Andrew Thompson
    Dec 13, 2006
  2. iPleb
    Replies:
    0
    Views:
    361
    iPleb
    Oct 9, 2007
  3. sunkrajesh
    Replies:
    0
    Views:
    1,139
    sunkrajesh
    Dec 7, 2008
  4. ORF3O
    Replies:
    2
    Views:
    158
    ORF3O
    Oct 14, 2005
  5. AJAX not working in FireFox

    , Sep 4, 2008, in forum: Javascript
    Replies:
    4
    Views:
    104
    GArlington
    Sep 5, 2008
Loading...

Share This Page