日期:2014-05-16  浏览次数:20691 次

求Ajax传参问题 - Web 开发 / Ajax
前台传给后台一个日期值[date],是String类型的,调试获取到值是:2011-12-14
到后台ashx内通过“context.Request["date"]”获取到的值变成了111-12-14

这是为什么?有什么方法可以获取到前台的那个值吗?

前台如下:

JScript code

$("#btnSubmitMoney").click(function () {
    var nowDate = ""; //当天日期
    var money = ""; //当天销售额
    var theDate = new Date();
    nowDate = theDate.getYear() + "-" + (theDate.getMonth() + 1) + "-" + theDate.getDate();
    money = $("#txtMoney").val();
    addNowMoney(nowDate, money);
});



JScript code

function addNowMoney(date, money) {
    $.post("ajax_API/ajaxapi.ashx", { fun: "AddMoney", date: date, money: money }, function (result) {
        if (result == "repeat") {
            alert("“" + date + "”记录已存在!");
        } else if (result == "success") {
            alert("提交成功");
        } else if (result == "failure") {
            alert("提交失败");
        } else {
            alert("未知错误");
        }
    });
}



后台是这样获取的:
在ashx中,context.Request["date"]也试过
C# code

string date = context.Request.Params["date"];



------解决方案--------------------
前台执行完提示的信息是什么。。。
------解决方案--------------------
nowDate = theDate.getYear() + "-" + (theDate.getMonth() + 1) + "-" + theDate.getDate();
=>
 nowDate = theDate.getFullYear() + "-" + (theDate.getMonth() + 1) + "-" + theDate.getDate();
--------------

string date = context.Request.Params["date"];
=>
string date = context.Request.Form["date"];
------解决方案--------------------
邮箱是什么,给你发个案例。
js.ajax调用webservice或者ashx;jquery.ajax()调用webservice或者ashx。