javascript---提交评论保存,js实现代码

<script type="text/javascript">
		
		//复选框选中和不选中切换
		$(".checkbox").click(function(){
			var state = $(this).attr('checked');
		     $(this).attr('checked',!state);
		});

		var productId = sessionStorage.productId; 
		console.log(productId);
		
		var orderId = sessionStorage.orderId;
		$(".mr20 a").text(orderId);
		
		var userId = sessionStorage.userId;
		console.log(userId);
		
		$("#comment_submit").click(function(){
			
			// 商品满意度
			var product_satisfaction = $("#select_tag option:selected").text();
			console.log(product_satisfaction);
			
			// 买家印象
			var Buyers_impression = "";
			 $(".checkbox:checked").each(function(){
				 var check_val = $(this).val();
				 Buyers_impression += check_val + ","
			 })
			console.log(Buyers_impression);
			 
			// 评价
			var comment = $("#product_comment").val();
			console.log(comment);
			
			$.ajax({
				url : "http://192.168.0.231:8099/comment",
				type : "POST",
				data : {
					"productSatisfaction" : product_satisfaction,
					"BuyersImpression" : Buyers_impression,
					"comment" : comment,
					"productId" : productId,
					"orderId" : orderId,
					"userId" : userId
				},
				success : function(data){
					alert("评价完成!");
				},
				error : function(data){
					alert("评价完成!");
				}
			})
			
		});
		
		$("#comment_check").click(function(){
			location.href = "http://www.atguigu.com/showComment.html?productId=" + productId +"&userId="+userId;
		});
		
		// 查询商品并遍历的ajax
		$.ajax({
			url : "http://manager.atguigu.com/restful/api/productTwo/" + productId,
			dataType : "jsonp",
			type : "GET",
			success : function(data){
				$(".p-img").html('<img src="/assess/14.jpg">');
				$(".p-name").text("图文无关");
				$(".p-price strong").text("$"+(data.price/100));
				$(".p-attr").text(data.title);
			},
			error : function(data){
				alert("查询失败!");
			}
		});
		
		var create_time = sessionStorage.createTime;
		$(".create_time").text(create_time);
		
		
			
		
</script>

 

转载于:https://my.oschina.net/u/3744350/blog/1593934

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值