【问题标题】:Get null data when pass parameter in query string in $.ajax在 $.ajax 中的查询字符串中传递参数时获取空数据
【发布时间】:2013-09-25 19:42:17
【问题描述】:

我使用 $.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 });
                }
            }
        });
    }

在这种情况下,我没有得到空数据,

是什么原因?

【问题讨论】:

  • 尝试将servicename: "change" 与密码值一起添加到 ajax 数据组件中。
  • 将内容类型添加到您的 ajax 方法中,例如 contentType: "application/json; charset=utf-8",
  • @AndreiV 当我这样做时,我的查询字符串在服务页面中为空
  • @VarunPaul,没有什么不同
  • 你能发布控制器代码吗(我假设它是 mvc)?没有它,很难知道那里发生了什么:)

标签: c# jquery asp.net ajax


【解决方案1】:

试试

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

也许是更好的方法

jquery ajax method returns null value

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-27
    • 2014-02-20
    相关资源
    最近更新 更多