Request not working in firefox

Asked

Viewed 34 times

1

I’m making an Ajax request, where it works on Chrome perfectly but firefox does not work.

He tells me that Event is not defined

function pegarValor() {
        dado =  event.srcElement.innerText;

        var XMLHttp =  generateXMLHttp();
        XMLHttp.open("get", "classes/getData.php?result=" + dado, true);
        XMLHttp.onreadystatechange = function () {

            if (XMLHttp.readyState == 4)
                if (XMLHttp.status == 200) {
                    data = XMLHttp.responseText.split("#");
                    if(XMLHttp.responseText == ""){

                        $(".conteudo-select").html("Não foi encontrado");
                    }else{
                        $("#txtRazaoSocial").val(data[0]);
                        $("#txtCNPJ").val(data[1]);

                        $(".conteudo-select").fadeOut(500);
                    }
                }
        };
        XMLHttp.send(null);

    }

Ai in HTML has a

<div onlick='pegarValor()'>

Obs: Me trying to do $("#id"). on('click',Function(){ ... }) didn’t work.

1 answer

1


A long time ago (I think more than a decade ago) the people of Internet Explorer decided that it would be a good idea to have a global variable called event, always filled with the data of the triggered event.

Whether this was a good idea is a matter of opinion. The fact is that the main browsers follow this idea, with the exception of Firefox. Source: MDN.

In your case, in order for the function to work in Firefox, you need to declare it to receive a parameter, thus:

function pegarValor(event) {
    dado =  event.srcElement.innerText;
    // resto do código

And if your function is called in hand and not by capturing an event, you need to assemble an object with the data you want and pass it explicitly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.