发送POST参数AJAX而不使用jQuery

时间:2018-04-04 16:53:24

标签: javascript ajax post

我想通过AJAX将POST参数发送到控制器,但是没有 jQuery。我该怎么办?



function myFunction() {
    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            document.getElementById("myDiv").innerHTML = this.responseText;
        }
    };
    //Add the POST parameters
    xhr.open("POST", "my_controller.php", true);
    xhr.send();
}

<button type="button" onclick="myFunction">Send POST parameters</button>
<div id="myDiv"></div>
&#13;
&#13;
&#13;

感谢您的帮助。

0 个答案:

没有答案
相关问题