浅谈$.ajax() 和$.post()

$.ajax({ })$.post()(jQuery对原生ajax的封装)同样都是ajax的异步请求:``

   <button onclick="sendJson()">原生Json数据交互测试</button>
    <button onclick="sendJson2()">Json数据交互测试</button>
    </body>
    <script type="text/javascript">
     function sendJson(){
    	 $.ajax({
    		 url:"${pageContext.request.contextPath }/item/jsontest.action",
    		 type:"post",
    		 data:'{"id":1,"name":"李四","price":2300,"createtime":"2017-09-09 12:23:09"}',
    		contentType:"application/json;charset=utf-8",
    		success:function(data){
    			alert(data.id+":"+data.name);
    		}
     
    	 })
     }
     function sendJson2(){
    	 
    	 $.post("${pageContext.request.contextPath }/item/jsontest2.action",
    			 {"id":1,"name":"张三","createtime":"2017-09-09 12:23:09"},function(data){
    		 alert(data.name);
    	 },"json")
     }
    </script>

参考网址:https://blog.csdn.net/weixin_39709686/article/details/78680754

猜你喜欢

转载自blog.csdn.net/weixin_43209201/article/details/86375194
今日推荐