zoukankan      html  css  js  c++  java
  • 在前台引用JSON对象

    <script type="text/javascript" src="js/jquery-1.11.0.min.js"></script>
    <script type="text/javascript" src="js/json2.js"></script>

    <script type="text/javascript">
    $(document).ready(function(){
    testRequestBody();
    });
    function testRequestBody(){
    $.ajax("${pageContext.request.contextPath}/hello",// 发送请求的URL字符串。
    {
    dataType : "json", // 预期服务器返回的数据类型。如果服务器返回不一致,报 parseError
    type : "post", // 请求方式 POST或GET
    // contentType:"application/json", // 发送信息至服务器时的内容编码类型
    contentType:"text/plain", // 发送信息至服务器时的内容编码类型

    // 发送到服务器的数据。

     data:JSON.stringify({ price:12399,name : "Spring MVC企业应用实战"}),

    //JSON.parse(jsonString);只有引用了 json2.js(这是一个开源文件,网上可以下载),才能使用JSON 对象


    // data:"Spring MVC企业应用实战",

    async: true , // 默认设置下,所有请求均为异步请求。如果设置为false,则发送同步请求
    // 请求成功后的回调函数。
    success :function(data){
    console.log(data);
    $("#id").html(data.description);
    $("#name").html(data.name);
    $("#author").html(data.price);
    },
    // 请求出错时调用的函数
    error:function(xhr,err,errObj){
    console.log(err);
    console.log(errObj);
    alert("数据发送失败");
    }
    });
    }
    </script>

  • 相关阅读:
    B. Ilya and Queries(前缀和)
    A. Cards for Friends(数学题)
    C. Given Length and Sum of Digits...(思维题)
    A. XORwice(水题)
    A. Raising Bacteria(位运算)
    最(cai)近(ji)总(shuo)结(hua)
    A. Road To Zero(水题)
    只要暴风骤雨才能使人迅速地成长
    Android Bitmap和Canvas学习笔记
    一些坑
  • 原文地址:https://www.cnblogs.com/jichen/p/8118372.html
Copyright © 2011-2022 走看看