我是靠谱客的博主 无聊汉堡,这篇文章主要介绍Javascript ajax (POST)请求方法,现在分享给大家,希望可以做个参考。

<script>
btn.onclick = function(){
            var xhr = new XMLHttpRequest()
            xhr.onreadystatechange = function(){
                if(xhr.readyState == 4 && xhr.status == 200){
                    console.log(xhr);
                    var res = JSON.parse(xhr.responseText)
                    console.log(res);               
                }
            }
            xhr.open('POST', '链接',true)
            xhr.setRequestHeader(
                'Content-type',
                'application/x-www-form-urlencoded'
            )
            var str = 'username=123&password=321'
            xhr.send(str)          
           }


</script>

最后

以上就是无聊汉堡最近收集整理的关于Javascript ajax (POST)请求方法的全部内容,更多相关Javascript内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(123)

评论列表共有 0 条评论

立即
投稿
返回
顶部