Obtener el resultado del archivo php sin usar jquery

Is this possible to get result from a php file without using jQuery ? i haven't permission to use Jquery and any other javaScript platform.

preguntado el 30 de enero de 12 a las 19:01

do you mean making an ajax call to php output for displaying? Of course you can, jQuery is just a framework that makes it easier for you, you would be stuck coding the ajax yourself, but you can always just search for an already made solution. -

@Jakub yes i already searched but i need some thing like jQuery .get() , i cant using lots of codes , i need an small routine -

Once I had a boss who also imposed not to use too much libraries in order to keep the size of the page small. Now I teach him JavaScript every Saturday )). The thing is when you don't use already established libraries, then you have to write more custom JavaScript. This eventually will lead to a greater size that would be if you used some library. This also can cause bugs that are dealt already in the libraries. -

2 Respuestas

Aquí hay un ejemplo:

function C_xmlObject() {
    var xml = null;

    try { xml = new ActiveXObject("Microsoft.XMLHTTP"); }
    catch(e) { try { xml = new ActiveXObject("MSXML2.XMLHTTP"); }
        catch(e) { try { xml = new XMLHttpRequest(); }
            catch(e) { } } }
    return xml;
}
function C_ajax(daten, url) {
    var xml = C_xmlObject();

    if(xml !== null) {
        xml.open('POST', url, true);
        xml.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
        xml.setRequestHeader('Content-length', daten.length);
        xml.setRequestHeader('Connection', 'close');
        xml.send(daten);
        xml.onreadystatechange = function() {
            if(xml.readyState === 4) {
                // Do something
            }
        }
    }
}

daten is for example "name=1&name2=Hello".

Edit: Version with prototype:

Object.prototype.ajax = function(daten, url, toElement, attributeName) {
    var xml = null;

    try { xml = new ActiveXObject("Microsoft.XMLHTTP"); }
    catch(e) { try { xml = new ActiveXObject("MSXML2.XMLHTTP"); }
        catch(e) { try { xml = new XMLHttpRequest(); }
            catch(e) { } } }

    if(xml !== null) {
        xml.open('POST', url, true);
        xml.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
        xml.setRequestHeader('Content-length', daten.length);
        xml.setRequestHeader('Connection', 'close');
        xml.send(daten);
        if(toElement !== null) {
            xml.onreadystatechange = function() {
                if(xml.readyState === 4) {
                    if(attributeName === null) {
                        toElement = xml.responseText;
                    } else {
                        toElement[attributeName] = xml.responseText;
                    }
                }
            }
        }
    }
}

This should work: ({}).ajax('value1=...', 'index.php', document.getElementById('id'), 'innerHTML');

Respondido el 31 de enero de 12 a las 00:01

thanks ! but i saw that later. i need a small routine or tiny trick to use inside my body section of page - bizzr3

Can you give me an example what the code should do? I think I can give you the answer. - user1150525

ok , something like <script>someobject.ajax('http://muhost.com/log.php?ip=x.x.x.x.&url=http://blah.com&12:22PM')</script> - bizzr3

can i use this as a function in <script> tag ? - bizzr3

or in totally i need just open this url without attention to its result http://muhost.com/log.php?ip=x.x.x.x.&url=http://blah.‌​com&12:22PM' - bizzr3

i use this one to send request with javascript and its works perfectly :

function httpGet(theUrl)
{
        var xmlHttp = null;

        xmlHttp = new XMLHttpRequest();
        xmlHttp.open( "GET", theUrl, false );
        xmlHttp.send( null );
        alert(xmlHttp.responseText);
}

and the html code :

<html>
<head>
<script type="text/javascript" src="log.js"></script>
</head>
<body>
        <a href="" onclick="httpGet('log.php?url=http://bizzare.com')">Send log</a>
</body>
</html>

Respondido el 31 de enero de 12 a las 10:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.