javascript - Getting TypeError : 'caller' , 'callee' 和 'arguments' properties may not be accessed on strict mode

标签 javascript jquery ajax

我有以下 jQuery 代码:

$(document).ready(function() {

  $('.btn-create-post-card').on('click', function(event) {
    event.preventDefault();
    let form_data = new FormData(),
      file = $('.input_file_button');
    // if(!file.val()) {
    //     alert('Please select postcard you want to send')
    // }
    form_data.append("file", file.prop('files')[0]);
    $.ajax({
      url: "/sendEmail",
      dataType: 'multipart/form-data',
      cache: false,
      contentType: false,
      processData: false,
      data: form_data,
      type: 'post',
      success: function(data) {
        alert('OK');
      },
      error: function(error, status) {
        console.log('here');
        console.log(error);
        alert(error);
      }
    });
  });
});

我收到这个错误:

TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them
    at Function.remoteFunction (:2:14)

控制台输出为:enter image description here

如您所见,响应成功,我以前经常使用 jQuery AJAX 调用,但从未遇到过这个问题。

更新:

控制台输出:

abort: ƒ (e)
    arguments: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.remoteFunction (<anonymous>:2:14)]
    caller: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.remoteFunction (<anonymous>:2:14)]
    length: 1
    name: "abort"
    prototype: {constructor: ƒ}
    __proto__: ƒ ()
    [[FunctionLocation]]: jquery.min.js:2
    [[Scopes]]: Scopes[3]
always: ƒ ()
    arguments: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.remoteFunction (<anonymous>:2:14)]
    caller: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.remoteFunction (<anonymous>:2:14)]
    length: 0
    name: "always"
    prototype: {constructor: ƒ}
    __proto__: ƒ ()
    [[FunctionLocation]]: jquery.min.js:2
    [[Scopes]]: Scopes[3]
catch: ƒ (e)
    arguments: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.remoteFunction (<anonymous>:2:14)]
    caller: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.remoteFunction (<anonymous>:2:14)]
    length: 1
    name: "catch"
    prototype: {constructor: ƒ}
    __proto__: ƒ ()
    [[FunctionLocation]]: jquery.min.js:2
    [[Scopes]]: Scopes[3]
done: ƒ ()
    arguments: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.remoteFunction (<anonymous>:2:14)]
    caller: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.remoteFunction (<anonymous>:2:14)]
    length: 0
    name: "add"
    prototype: {constructor: ƒ}
    __proto__: ƒ ()
    [[FunctionLocation]]: jquery.min.js:2
    [[Scopes]]: Scopes[3]
fail: ƒ ()
    arguments: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.remoteFunction (<anonymous>:2:14)]
    caller: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.remoteFunction (<anonymous>:2:14)]
    length: 0
    name: "add"
    prototype: {constructor: ƒ}
    __proto__: ƒ ()
    [[FunctionLocation]]: jquery.min.js:2
    [[Scopes]]: Scopes[3]
getAllResponseHeaders: ƒ ()
    arguments: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.remoteFunction (<anonymous>:2:14)]
    caller: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.remoteFunction (<anonymous>:2:14)]
    length: 0
    name: "getAllResponseHeaders"
    prototype: {constructor: ƒ}
    __proto__: ƒ ()
    [[FunctionLocation]]: jquery.min.js:2
    [[Scopes]]: Scopes[3]
getResponseHeader: ƒ (e)
    arguments: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.remoteFunction (<anonymous>:2:14)]
    caller: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.remoteFunction (<anonymous>:2:14)]
    length: 1
    name: "getResponseHeader"
    prototype: {constructor: ƒ}
    __proto__: ƒ ()
    [[FunctionLocation]]: jquery.min.js:2
    [[Scopes]]: Scopes[3]
overrideMimeType: ƒ (e)
    arguments: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.remoteFunction (<anonymous>:2:14)]
    caller: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.remoteFunction (<anonymous>:2:14)]
    length: 1
    name: "overrideMimeType"
    prototype: {constructor: ƒ}
    __proto__: ƒ ()
    [[FunctionLocation]]: jquery.min.js:2
    [[Scopes]]: Scopes[3]
pipe: ƒ ()
    arguments: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.remoteFunction (<anonymous>:2:14)]
    caller: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.remoteFunction (<anonymous>:2:14)]
    length: 0
    name: "pipe"
    prototype: {constructor: ƒ}
    __proto__: ƒ ()
    [[FunctionLocation]]: jquery.min.js:2
    [[Scopes]]: Scopes[3]
progress: ƒ ()
    arguments: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.remoteFunction (<anonymous>:2:14)]
    caller: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.remoteFunction (<anonymous>:2:14)]
    length: 0
    name: "add"
    prototype: {constructor: ƒ}
    __proto__: ƒ ()
    [[FunctionLocation]]: jquery.min.js:2
    [[Scopes]]: Scopes[3]
promise: ƒ (e)
    arguments: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.remoteFunction (<anonymous>:2:14)]
    caller: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.remoteFunction (<anonymous>:2:14)]
    length: 1
    name: "promise"
    prototype: {constructor: ƒ}
    __proto__: ƒ ()
    [[FunctionLocation]]: jquery.min.js:2
    [[Scopes]]: Scopes[3]
readyState: 4
responseText: ""can't upload file""
setRequestHeader: ƒ (e,t)
    arguments: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.remoteFunction (<anonymous>:2:14)]
    caller: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.remoteFunction (<anonymous>:2:14)]
    length: 2
    name: "setRequestHeader"
    prototype: {constructor: ƒ}
    __proto__: ƒ ()
    [[FunctionLocation]]: jquery.min.js:2
    [[Scopes]]: Scopes[3]
state: ƒ ()
    arguments: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.remoteFunction (<anonymous>:2:14)]
    caller: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.remoteFunction (<anonymous>:2:14)]
    length: 0
    name: "state"
    prototype: {constructor: ƒ}
    __proto__: ƒ ()
    [[FunctionLocation]]: jquery.min.js:2
    [[Scopes]]: Scopes[3]
status: 200
statusCode: ƒ (e)
    arguments: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.remoteFunction (<anonymous>:2:14)]
    caller: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.remoteFunction (<anonymous>:2:14)]
    length: 1
    name: "statusCode"
    prototype: {constructor: ƒ}
    __proto__: ƒ ()
    [[FunctionLocation]]: jquery.min.js:2
    [[Scopes]]: Scopes[3]
statusText: "OK"
then: ƒ (t,r,i)
    arguments: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.remoteFunction (<anonymous>:2:14)]
    caller: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.remoteFunction (<anonymous>:2:14)]
    length: 3
    name: "then"
    prototype: {constructor: ƒ}
    __proto__: ƒ ()
    [[FunctionLocation]]: jquery.min.js:2
    [[Scopes]]: Scopes[3]
__proto__: Object

最佳答案

我认为不是严格模式的错误,只是控制台无法在严格模式下获取参数数组的内容。状态为 200,因此看起来 ajax 调用有效,但响应文本显示“无法上传文件”,因此我认为错误出在服务器端。

使用 TypeError 示例更新:

TypeError 只是说控制台在使用严格模式时无法获取参数数组的值。这不是代码错误。图中的简单示例演示了这一点。

Example of TypeError

关于javascript - Getting TypeError : 'caller' , 'callee' 和 'arguments' properties may not be accessed on strict mode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52298691/

相关文章:

javascript - 如何使用左/右循环浏览div

php - Sql INNER JOIN 无法正常工作,如何使用 Jquery/Ajax 在 html 表单上显示上传的文件

javascript - 如何将参数从 JSP 传递到 Struts 2 操作

javascript - 使用 .onclick 在幻灯片中显示正确的文本

php - 如何登录网站或访问现有 cookie 以使用 file_get_contents

javascript - 如何解析 webmethod 中以数组列表返回的 Json 结果?

javascript - jQuery 对话框和 ajax 回传

jquery - 新手: What does jQuery. ajaxSetup 'beforeSend' 做什么?

javascript - jquery ajax get 没有数据时显示错误信息

php - jQuery/jqGrids/提交表单数据烦恼