Jump to content

Archived

This topic is now archived and is closed to further replies.

baiju

ajax not workng in morzilla firefox

Recommended Posts


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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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;
}
}

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.