0

i just created ajax script which sends data to php file but, something is wrong coz when i send javascript var variable "browserLang ", i get an error that not defined. Here is my javascript:

function SetLang() 
{
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    var browserLang = navigator.language || navigator.userLanguage;
    xmlhttp.open("POST","style/wps-light/datalife3.php",true);
    xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlhttp.send("BrowserLang=" + encodeURIComponent(userLang));
}

So what am i doing wrong?

1 Answer 1

6

you define browserLang but send userLang

function SetLang() 
{
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    var browserLang = navigator.language || navigator.userLanguage;
    xmlhttp.open("POST","style/wps-light/datalife3.php",true);
    xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlhttp.send("BrowserLang=" + encodeURIComponent(browserLang));
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.