在jQuery中将点击(this)的值传递给ajax成功 [英] Passing value from click (this) into ajax success in jQuery

查看:100
本文介绍了在jQuery中将点击(this)的值传递给ajax成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这种情况:

$(document).ready(function(){
                $(document).on('click','.btn', function() {
                    var this = $(this);
                    $.ajax({
                        type: "POST",
                        url: "{{ path('some-path') }}",
                        data: {'data' : 'some-data'},
                        success: function(data)
                        {   
                            var value_from_click = this;

                        }
                    });
                });
            });

我怎样才能将价值从这个直接转化为ajax成功呢?有什么简单,简单的解决方案吗?

How can I pass the value from this straight into ajax success? Are there any straightforward, easy solutions?

推荐答案

只需重命名变量:

var this = $(this); 

var this2 = $(this);

this是语言关键字,具有特殊含义,请为变量使用其他名称.

this is a language keyword and has a special meaning, use another name for the variable.

这篇关于在jQuery中将点击(this)的值传递给ajax成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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