ajax传递值

前台传给后台:

var warehouseReceiptJsonStr = JSON.stringify(receipt);
        var actionUrl = ($("#"+formId).attr("action"));
        $.ajax({
            url:actionUrl,
            type : "post",
            dataType : "json",
            data : {"method:jsonSave":'',
                warehouseReceiptDetailsJsonStr:warehouseReceiptDetailsJsonStr,
                warehouseReceiptJsonStr:warehouseReceiptJsonStr},
            success : function(data) {
                eval('rtn = '+data.responseText);
                if($('#warehouseReceipt_id').val()=="")
                    showPublicMsg("保存入库单成功!");
                else
                    showPublicMsg("修改入库单成功!");
                $('#warehouseReceipt_id').val(rtn.id);
                $('#warehouseReceipt_serialNo').val(rtn.serialNo);
                $('#displayButtonSpan').css('display','');
                jQuery('#list_receipt').jqGrid('clearGridData',false);
                jQuery("#list_receipt").trigger("reloadGrid");
            }
        });

        if($('#recordingVoucher_contractCode').val() != ""){
            contractCode=$('#recordingVoucher_contractCode').val();
        }
        $.ajax({
            url: "${ ctx}/scm/texBuyContract.action?method:addAlreadyQuantity",
            type: "post",
            data:{warehouseReceiptDetailsJsonStr:warehouseReceiptDetailsJsonStr,
                contractCode:$("#recordingVoucher_contractCode").val(),
                contractId:$("#contractCode_id").val()
            },
            success:function(data){
                showPublicMsg("传到了texBuy!");
            }
        });

后台传给前台

public void addAlreadyQuantity(){
        String contractCode = (String) this.getParameter("contractCode", String.class);
        Long contractId = (Long) this.getParameter("contractId", Long.class);
//      System.out.println("contractId"+contractId);
        JSONArray warehouseReceiptDetailsJson = JSONArray.fromObject(warehouseReceiptDetailsJsonStr);
//      System.out.println("===============");
//      System.out.println("contractCode"+contractCode);
        for (int i = 0; i < warehouseReceiptDetailsJson.size(); i++) {
            JSONObject detailJson = warehouseReceiptDetailsJson.getJSONObject(i);
            WarehouseReceiptDetail detail = (WarehouseReceiptDetail) JSONObjectUtils.toBean(detailJson, WarehouseReceiptDetail.class,manager);
            Float quantity = detail.getQuantity();
            Long productId=detail.getProduct().getId();
//          System.out.println("=========");
//          System.out.println("quantity"+quantity);
//          System.out.println("productId"+productId);
            if(contractCode!=null){
                TexBuyContractItem d = texBuyContractItemManager
                        .queryUniqueResult(
                                "from TexBuyContractItem where contract.id=? and product.id=?",
                                contractId, productId);
                Float alreadyQuantityItem;
                if(d.getAlreadyQuantity()==null){
                    alreadyQuantityItem=Float.valueOf(0);
                }else{
                    alreadyQuantityItem=(Float)d.getAlreadyQuantity();
                }



                Float addItem=alreadyQuantityItem+quantity;
//              System.out.println("addItem"+addItem);
                d.setAlreadyQuantity(addItem);
                texBuyContractItemManager.save(d);


                String hql = "from TexBuyContract where id=?";
                TexBuyContract c = texBuyContractManager.queryUniqueResult(hql,
                        contractId);

                Float alreadyQuantity;
                if(c.getAlreadyQuantity()==null){
                    alreadyQuantity=Float.valueOf(0);
                }else{
                    alreadyQuantity=(Float)c.getAlreadyQuantity();
                }
//              
//              System.out.println("================");
//              System.out.println("alreadyQuantity"+alreadyQuantity);

                Float add=alreadyQuantity+quantity;
//              System.out.println("after add"+add);
                c.setAlreadyQuantity(add);
                texBuyContractManager.save(c); 

//              

//              String sql=
//              "SELECT t.f_already_quantity AS f_already_quantity FROM t_tex_buy_contract t where t.f_id="+contractId;

            }
        }

    }
JSONObject json = new JSONObject();
        json.put("id", warehouseReceipt.getId());
        json.put("serialNo", warehouseReceipt.getSerialNo());
        responseWrite(json.toString());

你可能感兴趣的:(Ajax,url)