欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

ajax post get调用c语言cgi程序

程序员文章站 2022-05-09 10:05:13
...

ajax post get调用c语言cgi程序

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>深圳光派管理后台</title>
    <script src="./lib/jquery.js"></script>
</head>

<body>
    <h1>It works!hahahahhahaha~</h1>
    <input type="button" onclick="save()" value="保存" />
    <input type="button" onclick="refresh()" value="刷新" />

    <script>
        function save() {
            $.ajax({
                type: 'POST',
                url: './cgi-bin/post.cgi',
                data: 'name:zhangzhen age:17 school:guangzhou sex:nan',
                dataType: "text",
                ContentType: "application/text; charset=utf-8",
                success: function(returnedData, status) {
                    if (status == "success") {
                        alert(returnedData);
                    }
                },
                error: function(msg) {
                    alert("访问失败:" + msg);
                }

            });
        }

        function refresh() {
            $.ajax({
                type: 'GET',
                url: './cgi-bin/post.cgi',
                data: 'name age school sex',
                dataType: "text",
                ContentType: "application/text; charset=utf-8",
                success: function(returnedData, status) {
                    if (status == "success") {
                        alert(returnedData);
                    }
                },
                error: function(msg) {
                    alert("访问失败:" + msg);
                }

            });
        }
    </script>
</body>

</html>