在$ .ajax中的查询字符串中传递参数时获取空数据

时间:2013-09-25 06:22:21

标签: c# jquery asp.net ajax

我使用$ .ajax将数据发送到Sql, 当我在查询字符串中传递参数时,我在数据值中得到null,

function refreshTime(options) {
        $.ajaxService({
            url: 'http://localhost:1549/Store/Pages/services.aspx?servicename=change,
            data: { oldpassword: $("#oldpassword").val(), newpassword: $("#newpassword").val() },
            onStartService: function () { $(".failed-message,.success-message").hide(); $("#submitchangepassword,#oldpassword,#newpassword,#confirmpassword").attr('disabled', 'disabled'); },
            onEndService: function () { $("#submitchangepassword,#oldpassword,#newpassword,#confirmpassword").removeAttr('disabled').not("#submitchangepassword").val(""); },
            onResponse: function (response) {
                if (response.result == '1') {
                    $.pushMessage({ message: 'success', messageClass: 'success-message', delay: 6000 });
                }
                else {
                    $.pushMessage({ message:'error ', messageClass: 'failed-message', delay: 8000 });
                }
            }
        });
    }

我在服务页面中获得了空数据

但是当我没有传递参数时,我得到了正确的数据值,

function refreshTime(options) {
        $.ajaxService({
            url: 'http://localhost:1549/Store/Pages/services.aspx,
            data: { oldpassword: $("#oldpassword").val(), newpassword: $("#newpassword").val() },
            onStartService: function () { $(".failed-message,.success-message").hide(); $("#submitchangepassword,#oldpassword,#newpassword,#confirmpassword").attr('disabled', 'disabled'); },
            onEndService: function () { $("#submitchangepassword,#oldpassword,#newpassword,#confirmpassword").removeAttr('disabled').not("#submitchangepassword").val(""); },
            onResponse: function (response) {
                if (response.result == '1') {
                    $.pushMessage({ message: 'success', messageClass: 'success-message', delay: 6000 });
                }
                else {
                    $.pushMessage({ message:'error ', messageClass: 'failed-message', delay: 8000 });
                }
            }
        });
    }

在这种情况下,我不会得到空数据,

是什么原因?

1 个答案:

答案 0 :(得分:0)

尝试

"{ 'oldpassword': '" + $("#oldpassword").val() + "', 'newpassword':'" + $("#newpassword").val() +"'}",

或者更好的方法

jquery ajax method returns null value