阅读背景:

为什么这个ajax脚本不会使用ajaxRequest.open调用后端php?

来源:互联网 
<html><head><title>Loses</title></head><body>

<script language="javascript" type="text/javascript">
function ajaxFunction() {
    var ajaxRequest;
    try{
        // Opera 8.0+, Firefox, Safari
        ajaxRequest = new XMLHttpRequest();
    }catch (e){
        // Internet Explorer Browsers
        try{
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        }catch (e){
            try {
                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            }catch (e){
                // Something went wrong
                alert("Your browser broke!");
                return false;
            }
        }
    }

    // Receive data from the server to update div
    ajaxRequest.onreadystatechange = function(){
        if(ajaxRequest.readyState == 4){
            var ajaxDisplay = document.getElementById('ajaxDiv');
            ajaxDisplay.value = ajaxRequest.responseText;
        }
    }

    // Get the value from user.
    if (!target) target = document.getElementById("name");
    var queryString = "?name=" + escape(target.value);

    var url = "db.php" + queryString;

    ajaxRequest.open("GET", url, true);
    ajaxRequest.send(null); 
}
</script>

<form name="myForm">
    Victim: <input type="text" id="name" name="name"/> <br/>
    <br/>
    <input type="button" onclick="getLoses()" value="Show Loses"/>
</form>

<div id="ajaxDiv">Results:</div>
<br>

</body></html>
<html><head><title>Loses</title></head><body>




你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: