Ajax+JSON传参的问题?在线等

问题描述

varinsId=$("#insId").val();varinsName=$("#insName").val();varinsMade=$("#insMade").val();varinsSeller=$("#insSeller").val();varinsBuyPrice=$("#insBuyPrice").val();varinsSellPrice=$("#insSellPrice").val();alert(insId+""+insName+""+insMade+""+insSeller+""+insBuyPrice+""+insSellPrice)$.get("saveUpdate.action?t="+newDate(),{"insId":insId,"insName":insName,"insMade":insMade,"insSeller":insSeller,"insBuyPrice":insBuyPrice,"insSellPrice":insSellPrice},function(data){alert("更新数据成功");});

//Action里面SaveUpdateListEntitysaveUpdate=newSaveUpdateListEntity();saveUpdate.setInsId(Integer.parseInt(insId));saveUpdate.setInsName(insName);saveUpdate.setInsMade(insMade);saveUpdate.setInsSeller(insSeller);saveUpdate.setInsSellPrice(Double.parseDouble(insSellPrice));saveUpdate.setInsBuyPrice(Double.parseDouble(insBuyPrice));this.getAllService().getUpdateService().saveUpdateList(saveUpdate);ServletActionContext.getResponse().setContentType("text/html");ServletActionContext.getResponse().setCharacterEncoding("utf-8");ServletActionContext.getResponse().getWriter().printf("success");ServletActionContext.getResponse().getWriter().flush();ServletActionContext.getResponse().getWriter().close();

问题是saveUpdate里面的值都是null而saveUpdate.setInsName(insName);里面从页面传过来的有值我想这里不能这么new实体么?还是什么原因!

解决方案

解决方案二:
你的意思是insName有值,saveUpdate.setInsName之后,savaUpadate实体中值还为空?
解决方案三:
你在后台用Stringaa=request.getParameter('insId');先看下aa有值没如果是null的话说明你的参数就没传到后台或者说你的struts的action没有写好
解决方案四:
saveUpdate.setInsName(insName);saveUpdate.setInsMade(insMade);saveUpdate.setInsSeller(insSeller);saveUpdate.setInsSellPrice(Double.parseDouble(insSellPrice));saveUpdate.setInsBuyPrice(Double.parseDouble(insBuyPrice));这些都拿到了!this.getAllService().getUpdateService().saveUpdateList(saveUpdate);saveupdate里面的值都null最后的赋值
解决方案五:
那就说名saveUpdate这个javabean是没有问题的不是这个实体的问题saveUpdateList这个方法发上来看下
解决方案六:
publicvoidsaveUpdateList(SaveUpdateListEntitysuleRef){InsListinsList=this.getAlldao().getInsListDao().findById(suleRef.getInsId());insList.setInsName(suleRef.getInsName());insList.setInsMade(suleRef.getInsMade());insList.setInsSeller(suleRef.getInsSeller());insList.setInsBuyPrice(suleRef.getInsBuyPrice());insList.setInsSellPrice(suleRef.getInsSellPrice());this.getAlldao().getInsListDao().attachDirty(insList);}

解决方案七:
其实从你的这些代码上看都是不应该有问题的publicvoidsaveUpdateList(SaveUpdateListEntitysuleRef){//参数suleRef这个没有问题是肯定的InsListinsList=this.getAlldao().getInsListDao().findById(suleRef.getInsId());insList.setInsName(suleRef.getInsName());insList.setInsMade(suleRef.getInsMade());insList.setInsSeller(suleRef.getInsSeller());insList.setInsBuyPrice(suleRef.getInsBuyPrice());insList.setInsSellPrice(suleRef.getInsSellPrice());//这个insList到这里也应该是更新ok了this.getAlldao().getInsListDao().attachDirty(insList);//这个就得看sql了呵呵}

解决方案八:
你action里面写的都是什么啊?麻烦贴出来看看!

时间: 2024-07-29 04:15:16

Ajax+JSON传参的问题?在线等的相关文章

jQuery的ajax传参巧用JSON使用示例(附Json插件)

jQuery的ajax调用很方便,传参的时候喜欢用Json的数据格式.比如: 复制代码 代码如下: function AddComment(content) { var threadId = $("#span_thread_id").html(); var groupId = $("#span_group_id").html(); var groupType = $("#span_group_type").html(); var title =

net-在Web用户控件ascx文件,怎么使用ajax调用后台方法并传参?

问题描述 在Web用户控件ascx文件,怎么使用ajax调用后台方法并传参? $.ajax({ type: "Post", url: "SetWidget.ascx/GetStr", data: "{'str':'我是','str2':'XXX'}", contentType: "application/json; charset=utf-8", dataType: "json", success: fun

关于strut2+ajax传参问题

问题描述 关于strut2+ajax传参问题 action中: /** * 判断用户是否存在 * @return * @throws Exception */ public String findByName() throws Exception { List userlist = adminService.searchStudent(username); System.out.println(userlist.size()+username); java.util.Map map = new

springMVC3.0(文件上传,@RequestMapping加参数,@SessionAttributes,@ModelAttribute,转发,重定向,数值获取,传参,ajax,拦截器)

1.项目包结构如下: 2.       spring配置文件springMVC.xml修改如下: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xml

ajax中data传参的两种方式分析

本文实例讲述了ajax中data传参的两种方式.分享给大家供大家参考,具体如下: 1. POST方式: /** * 订单取消 * @return {Boolean} 处理是否成功 */ function orderCancel(orderId, commant){ var flag = false; $.ajax({ type: "POST", url: "../order/orderCancel.action", //orderModifyStatus data:

ajax中data传参的两种方式分析_AJAX相关

本文实例讲述了ajax中data传参的两种方式.分享给大家供大家参考,具体如下: 1. POST方式: /** * 订单取消 * @return {Boolean} 处理是否成功 */ function orderCancel(orderId, commant){ var flag = false; $.ajax({ type: "POST", url: "../order/orderCancel.action", //orderModifyStatus data:

技术-关于JS调取服务和ajax获取url传参的问题

问题描述 关于JS调取服务和ajax获取url传参的问题 10.110.20.192:8080/BeijingSelling/services/hello?user=1244这是内网的服务地址 连接内网后在浏览器输入以上URL会在界面出现 Hello,1224. 就一个参数user,显示他的值:不输入则显示vistor 如何利用ajax或者其他技术获取user的值. 希望各位帮帮忙,确实查过不少资料,然后都是在本页面中获取URL的值,并不能解决我的问题. 解决方案 这个跨页需要服务器才能获取.然

ajax-Asp.net MVC Ajax post 传json格式数据控制器如何接收

问题描述 Asp.net MVC Ajax post 传json格式数据控制器如何接收 这是我的ajax代码 这是我要传的数据 这是我的控制器方法 求大师解惑,我的控制器方法里该如何接收这些值啊? 解决方案 http://www.jb51.net/article/23354.htmhttp://www.jquery001.com/pass-json-data-in-asp.net-mvc3.html 解决方案二: http://www.cnblogs.com/kissdodog/archive/

ajax传参问题-ajax向servlet传参问题

问题描述 ajax向servlet传参问题 在一个ajax中能不能同时出现两种传参方式 我现在试的结果是 直接在url中加一个参数,然后在data:{"data":dataFromAjax}中再加一个参数 在servlet中debug看到 值接收到URL中的参数 这是不是说 在同一个ajax中只能出现一种参数传递方式 且URL传参优先级比较高