$ .ajax问题-未捕获的TypeError:非法调用 [英] $.ajax issue - Uncaught TypeError: Illegal invocation

查看:146
本文介绍了$ .ajax问题-未捕获的TypeError:非法调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我有以下内容:

function sendUserfNotes()
    {
        $.ajax({
        type: "POST",
        url: '/pcg/popups/grabnotes.php',
        data:
        {
            'nameNotes': notes_name,
        },
        success: function() {

             }
    });
    }

我正在尝试将值-notes_name发送到.php文件,以便可以使用GET [''],但出现奇怪的错误-Uncaught TypeError: Illegal invocation

I am trying to send a value - notes_name over to a .php file so I can use GET[''] but I get a weird error - Uncaught TypeError: Illegal invocation

notes_name是根据是否单击链接而在脚本底部定义的

the notes_name is defined at the bottom of the script based on if a link is clicked

代码:

$(document).ready(function () {
    $(".NotesAccessor").click(function () {
        notes_name = $(this).parent().parent().find(".user_table");
      run();
    });
    });

run()在Jquery ui中触发一个对话框,并在出现错误的地方运行此函数.

The run() triggers a dialog box in Jquery ui and runs this function where I am getting the error.

我不知道为什么要得到这个?

I don't know why I am getting this?

大卫

更新:

我认为这是将JavaScript值定义为"nameNotes":notes_name是在此代码之后定义的,但这无关紧要.那我该如何分配JavaScript变量呢?

I figured that it is with defining the JavaScript value to 'nameNotes': the notes_name is defined after this code but that shouldn't matter. So how would I assign the JavaScript variable to this?

推荐答案

这是因为您要为notes_name而不是字符串(或其他一些基本类型,例如int)分配一个jQuery对象.这会导致$.ajax调用失败.根据.user_table元素包含的内容,使用.value().text()(或类似的东西)提取所需的字符串,而不使用jQuery对象.

It's because you're assigning a jQuery object to notes_name, instead of a string (or some other basic type, like an int). This causes the $.ajax call to fail. Depending on what the .user_table element contains, use either .value() or .text() (or something of the sort) to extract the desired string instead of using a jQuery object.

这篇关于$ .ajax问题-未捕获的TypeError:非法调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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