日期:2014-05-17  浏览次数:20394 次

jQuery.ajax中获取不到返回值,返回值是从数据库中查询出来的
js页中的代码:
JScript code

function SaveClick() {
    var Price1 = 0;
    for (var i = 1; i <= 10; i++) {
        var SumPrice = $("#txtSumPrice" + i).val();
        if (SumPrice != "") {
            Price1 = Price1 + parseFloat(SumPrice);

        }
    }
    var SupplierId1 = parseInt($("#ddSupplierList").val());
    var Performance1 = "1";
    var Time2 = $("#Calendar").val().replace(/-/g, "/");
    $.ajax({ //利用Ajax调用Web服务中的数据,实现与后台交互
        type: "POST",
        contentType: "application/json;utf-8",
        url: "WebService.asmx/addPurchaseOrders",
        data: "{ 'SupplierId' :'" + SupplierId1 + "', 'Price' :'" + Price1 + "', 'Performance' :'" + Performance1.toString() + "', 'Time1':'" + Time2 + "'}",
        //data: "{ 'SupplierId' :" + SupplierId1 + ", 'Price' :" + Price1 + ", 'Performance' :" + Performance1.toString() + ", Time1:'" + Time2 + "'}",
        //data: "{ 'SupplierId' :" + SupplierId1 + ", 'Price' :" + Price1 + ", 'Performance' :" + Performance1 + "}",
        dataType: 'json',
        anysc: false,
        success: function (data) {
            alert("ok");
           // alert(data.d);
            //SaveClickContent(data.d);

        },
        error: function (XMLResponse) {
            alert(XMLResponse.responseText);
            alert("false");
        }
    })


}



WebService.asmx页中的方法
C# code

[WebMethod]
    public string addPurchaseOrders(int SupplierId, decimal Price, string Performance, string Time1  )
    {
        
      string str="";
       BLL.PurchaseOrder bll = new BLL.PurchaseOrder();
       Model.PurchaseOrder model = new Model.PurchaseOrder();
       model.SupplierId = SupplierId;
       model.Price = Price;
       if (Performance == "1")
       {
           model.Performance = "保存";
       }
       model.RecTime = DateTime.Parse(Time1);
       if (bll.Add(model))
       {
           str = bll.SearchLastId().ToString();


           return str;
       }
      
        return str;
    }




------解决方案--------------------
你把你QQ号码私信我,我加你。以后可以讨论技术