My ajax in safari browser does not work

Asked

Viewed 183 times

0

well, it enters the requisicao, returns the data correctly, but the moment I use the . appendchild it does not fill... OBS: in Chrome it works......

and on the console it gives the following error:

TypeError: 'undefined' is not a function (evaluating 'document.getElementById("procuraCPF").append(li)')

function IniciaAjax() {
        var HTTP_REQUEST;
        try {
            HTTP_REQUEST = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e) {
            try {
                HTTP_REQUEST = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (ex) {
                try {
                    HTTP_REQUEST = new XMLHttpRequest();
                    HTTP_REQUEST.overrideMimeType('text/html');
                }
                catch (exc) {
                    alert("Esse browser não tem recursos para uso do Ajax");
                    HTTP_REQUEST = null;
                }
            }
        }
        return HTTP_REQUEST;
    }

    function meuPrimeiroAjax(textoo) {
        ajax = IniciaAjax();

        if (ajax) {
            ajax.onreadystatechange = function () {
                if (ajax.readyState == 1) { }
                if (ajax.readyState == 4) {
                    var data = JSON.parse(ajax.responseText);
                    document.getElementById('procuraCPF').innerHTML = "";
                    var option
                    for (var i in data) {
                        option = document.createElement("option");
                        var t = document.createTextNode(data[i].nome);
                        li.appendChild(t);
                    }
                    document.getElementById("procuraCPF").append(li);
                    //procuraCPF eh uma div
                }
            }
            dados = 'cpf=' + textoo;
            ajax.open('POST', '/Cliente/buscarClientesCPFS/', true);
            ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            ajax.send(dados);
        }
    }
        $(document).on('keyup', '#inputCPF', function () {
            $("#procuraNome").hide();
            $("#procuraCPF").show();
            var text = $("#inputCPF").val();
            meuPrimeiroAjax(text);

        });
  • Dude, for at least 8 years I haven’t seen anyone use this type of ajax request, checking the Activexobject :D old but gold...

  • suggestion... uses jquery that will make your life a lot easier... and if it is at the level of learning it is no longer used...

  • Denial of the unnecessary question, despite an old request method, continues as a valid question and no duplicates on this site.

  • Gustavo, in your question you included the jquery tag, is this your project using jquery? Could also post your HTML code, to help us?

  • i switched to requests with jquery, and returned the following error: Typeerror: 'Undefined' is not a Function (evaluating 'e. getattribute("type")')

1 answer

0

  • I need to use ajax as it is a standard of my company

Browser other questions tagged

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