相关疑难解决方法(0)

在AJAX中获取GET和POST?

为什么AJAX中存在GET和POST请求,因为它不会影响页面URL?在AJAX中通过GET传递敏感数据会有什么不同,因为数据没有反映到页面URL?

ajax post get http

22
推荐指数
5
解决办法
2万
查看次数

使用参数从XMLHttp发布POST

我正在尝试将数据发布到PHP页面并检查响应.这是一个例子.这段代码有什么问题?

的index.html

<html>
<head>
    <title>Post Ajax</title>
    <script type="text/javascript">
        function post(foo, bar) {
            var xmlhttp = new XMLHttpRequest();

            xmlhttp.onreadystatechange = function() {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    alert(xmlhttp.responseText);
                }
            }

            xmlhttp.open("POST", "ajax.php", true);
            xmlhttp.send("foo=" + foo + "&bar=" + bar);
        }
    </script>
</head>
<body>
    <input type="button" value="Click me" onclick="post('one','two');" />
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

ajax.php

<?php
if (array_key_exists('foo', $_POST) && array_key_exists('bar', $_POST)) {

    $foo = $_POST['foo'];
    $bar = ($_POST['bar']);
    // do stuff with params

    echo 'Yes, it works!';

} …
Run Code Online (Sandbox Code Playgroud)

javascript php ajax

10
推荐指数
1
解决办法
3万
查看次数

标签 统计

ajax ×2

get ×1

http ×1

javascript ×1

php ×1

post ×1