12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Title</title>
- <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
- </head>
- <script>
- function send1() {
- let id = $("#id").val();
- let name = $("#name").val();
- // $.ajax({
- // //url
- // url: 'test2',
- // //参数
- // data: { a: 100, b: 100 },
- // //请求参数
- // type: 'post',
- // //响应体结果
- // dataType: 'json',
- // contentType: 'application/json;charset=UTF-8',
- // //成功的回调
- // success: function (data) {
- // res = JSON.stringify(data);
- // console.log(data);
- // },
- // error: function () {
- // console.log('出错了!!');
- // }
- // });
- $.ajax({
- url: "test2",
- type: "post",
- //data表示发送的数据
- data: JSON.stringify({username: id, password: name}),
- dataType: 'json',
- contentType: 'application/json;charset=UTF-8',
- success: function (data) {
- // alert(data)
- // // alert(JSON.stringify(data));
- $('.result').text(JSON.stringify(data));
- // for (let i = 0; i < data.length; i++) {
- // $('.result').text(data[i].username);
- // }
- }
- });
- }
- </script>
- <body>
- <form>
- 学号:<input id="id" type="text"><br>
- 姓名:<input id="name" type="text"><br>
- <input type="button" value="提交json数据" onclick="send1()">
- </form>
- <div class="result"></div>
- </body>
- </html>
|