첫 번째 POST JSON 데이터 페이지

2082 단어
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<title>My jQuery JSON Web Page</title>
<head>
    <meta charset="utf-8"/>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script type="text/javascript">

        JSONTest = function () {

            var oldFooter = document.forms["myForm"]["oldFooter"].value;
            var footer = document.forms["myForm"]["footer"].value;
            var id = document.forms["myForm"]["id"].value;

            $.ajax({
                url: "http://localhost:8080/r/saveFooter",
                type: "POST",
                data: JSON.stringify({"oldFooter": oldFooter, "footer": footer, "id": id}),
                dataType: "json",
                contentType: "application/json;charset=utf-8",
                success: function (result) {
                    alert(JSON.stringify(result));
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    alert("hello world");
                    alert(xhr.status);
                    alert(thrownError);
                }
            });
        };

    </script>
</head>
<body>

<h1>My jQuery JSON Web Page</h1>

<%--<button type="button" onclick="JSONTest()">JSON</button>--%>

<form name="myForm" onsubmit="return JSONTest()" method="post">
    oldFooter: <input type="text" name="oldFooter">
    footer:<input type="text" name="footer">
    id:<input type="text" name="id">
    <input type="submit" value="Submit">
</form>

</body>
</html> 

좋은 웹페이지 즐겨찾기