Get result from php file without usig jquery

前端 未结 2 1435
借酒劲吻你
借酒劲吻你 2020-12-22 07:05

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.

相关标签:
2条回答
  • 2020-12-22 07:53

    Here is an example:

    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');

    0 讨论(0)
  • 2020-12-22 07:53

    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>
    
    0 讨论(0)
提交回复
热议问题