$('#delete').on('click', function(e){

      var id = '123';

      // layer.confirm('confirm delete?', {
      //     btn: ['ok','cancel'] //buttons
      // }, function(){
          $.ajax({
              type: 'post',
              url: '/test', // ===== could get id =====
              dataType: 'json'
          })
          .done(function(data){
              if(data.code === 1){
                  debugger // ===== could't get id ? ======
                  layer.msg('delete success', {icon: 1});
              }else{
                  layer.msg('success fail', {icon: 1});
              }
          })
          .fail(function(err){
              layer.msg('success fail', {icon: 1});
          })
      // })

    })

I use $.ajax().done(). when done fired, could't get outer variable "id" in line about "debugger" ?

我使用$ . ajax().done()。当你被解雇时,你无法在“调试器”中得到外部变量“id”吗?

For reslove "It looks like your post is mostly code; please add some more details. ", add some words. Actually, I explain this problem is clear.

对于reslove,看起来你的文章大部分是代码;请补充一些细节。”,添加一些文字。实际上,我解释这个问题很清楚。

1 个解决方案

#1


2

The Javascript interpreter will only capture variables in a closure if they're actually used in the inner function.

如果在内部函数中实际使用了变量,Javascript解释器将只捕获闭包中的变量。

If you change your function to use id anywhere, it will appear in the debugger.

如果您将函数更改为在任何地方使用id,它将出现在调试器中。

更多相关文章

  1. 通过调用返回参数的本地函数来构建Ajax Data部分
  2. Jquery ajax回调函数不执行
  3. JQUERY组装对象并调用自身函数改变自己的属性
  4. Angular ng-show不会根据函数返回值显示/隐藏
  5. 未捕获的ReferenceError:函数未定义,它标记
  6. 我怎么能用javascript编写这个简短的函数?
  7. 你能告诉为什么javascript函数没有在profile.php的提交按钮中执
  8. 使用window.open将变量传递给新的HTML
  9. JQuery函数不能用于初始触发器

随机推荐

  1. C语言中的指针有什么作用
  2. c语言程序中的基本功能模块为什么?
  3. C语言的三种基本程序结构是什么
  4. c语言源文件经过编译后生成文件的后缀是
  5. c语言是一种什么的程序设计语言?
  6. c语言指针用法有哪些
  7. c语言中,char型数据是以什么形式存储的?
  8. C语言怎么合并两个有序链表
  9. c语言程序的执行总是起始于什么?
  10. vc++6.0怎么新建c语言文件