使用jQuery ajax json响应? [英] Use Jquery ajax json response?

查看:95
本文介绍了使用jQuery ajax json响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

:具有如下所示的ajax请求:

:have an ajax request looking like this :

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

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

So if the function is successfull, the class "disabled" is removed. However, my function returns the following json :

{"row":"fze684fz6f4ez68f4ze"}

我想获取此值,以便以后可以使用它将其添加到数据元素,即我想将其添加到单击的元素data-row ="fze684fz6f4ez68f4ze"

I want to get this value so I can use it later "add it to a data element, i.e I want to add to the clicked element data-row="fze684fz6f4ez68f4ze"

我该如何管理?我自己弄不清楚,我正在发现AJAX.

How can I manage this ? I can't figure out by myself, I'm discovering AJAX.

非常感谢您的帮助!

推荐答案

如果希望获取json,建议设置dataType. 任何方式都要注意上下文. this可能有问题.

It's recommend to set dataType if you excpect to get json . Any way pay attention to the context. It might be a problem with 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);
    }
});

这篇关于使用jQuery ajax json响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆