使用Jquery ajax json响应?

Zip*_*plo 3 ajax jquery json

:有一个像这样的ajax请求:

$.ajax({
          url: "/users/action/",
          type: "POST",
          data: myData,
          context: this,
          error: function () {},
          success : function () {
        $(this).removeClass('disabled');
          }
        });
Run Code Online (Sandbox Code Playgroud)

因此,如果函数成功,则删除"禁用"类.但是,我的函数返回以下json:

{"row":"fze684fz6f4ez68f4ze"}
Run Code Online (Sandbox Code Playgroud)

我想得到这个值,以便我以后可以使用它"将它添加到数据元素,即我想添加到点击的元素data-row ="fze684fz6f4ez68f4ze"

我该怎么办呢?我不知道自己,我发现了AJAX.

非常感谢你的帮助 !

Dvi*_*vir 8

dataType如果您想要获得json,建议设置.任何方式都要注意上下文.这可能是一个问题this.

$.ajax({
    url: "/users/action/",
    type: "POST",
    data: myData,
    context: this,
    error: function () {},
    dataType: 'json',
    success : function (response) {
        $(this).removeClass('disabled');
        $(this).data("row",response.row);
    }
});
Run Code Online (Sandbox Code Playgroud)