Jump to content


Photo

ajax not workng in morzilla firefox


  • Please log in to reply
2 replies to this topic

#1 baiju

baiju
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 03 October 2006 - 05:59 AM


my prob is ajax not working in morzilla firefox..
but this same code having no prob with internet explorer..

here is my javascript code


function createRequestObject()
{
    if (window.XMLHttpRequest) { // Mozilla, Safari, Opera...
        var xmlhttp = new XMLHttpRequest();
        if (xmlhttp.overrideMimeType)
xmlhttp.overrideMimeType('text/xml');
    }
else if (window.ActiveXObject)
{ // IE
        try {
            var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }

    if (!xmlhttp) {
        alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }
return xmlhttp;
}

var http = createRequestObject();
function sendRequest() {

var name = document.getElementById('name').value;
var email = document.getElementById('email').value;
var ph = document.getElementById('ph').value;
var addr = document.getElementById('addr').value;
var descr = document.getElementById('descr').value;
http.open('post', 'mail.php');
http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
//alert('field='+field+'&field1'=field1);
http.send('name='+name+'&email='+email+'&ph='+ph+'&addr='+addr+'&descr='+descr);
//http.send('field1='+field1);
http.onreadystatechange = handleDetails;
}

function handleDetails() {
    if (http.readyState == 4) {
    var response = http.responseText;
document.getElementById('test').innerHTML = response;
}
}


#2 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 03 October 2006 - 10:17 AM

FF is realy picky..lol. I have had many problems with it.. Well not so much with Fire Fox but my messy code.

I see that you have placed some alerts throughout the script. That is the best way that I know of to debug.

Have you looked at the javascript console? Is it displaying any errors?

Are you sure that you are calling the sendRequest function correctly..?

If you post a link I will take a look at it with FF and Opera to see if I can find any errors.

Good Luck,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#3 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 03 October 2006 - 10:47 AM

this is my ajax obj creation function... I have no probs with it so far - works in IE FF Opera - not tested safari yet!

function GetXmlHttpObject(handler)
{
var objXmlHttp=null;

if (window.ActiveXObject)  // ActiveX version
{
try
{
objXmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
objXmlHttp.onreadystatechange=handler;
return objXmlHttp;
}
catch(e)
{
alert("Error. Scripting for ActiveX might be disabled");
return;
}
}
else if (window.XMLHttpRequest)    // Object of the current windows
{
objXmlHttp=new XMLHttpRequest();
objXmlHttp.onload=handler;
objXmlHttp.onerror=handler;
return objXmlHttp;
}
}
follow me on twitter @PHPsycho




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users