【问题标题】:jQuery $.post TypeError: e.type is not a functionjQuery $.post TypeError:e.type 不是函数
【发布时间】:2012-08-30 06:22:08
【问题描述】:

我正在尝试为 ZetaBoards 论坛软件构建反馈脚本,我创建了一个 $.post 函数,当我尝试通过单击提交按钮提交表单时,它只返回 'TypeError: e.type is not Firebug 中的一个函数。

这是我的代码:

<script type="text/javascript">
    var forumID = '1701794';

    if (location.href.indexOf('/profile/') !== -1) {
        $('table.profile:last').after('<form id="feedback_form"><table class="profile" id="feedback"><thead><tr><th colspan="4">Feedback</th></tr></thead><tbody><tr><th colspan="4">Overall Rating: # (Positive: #, Neutral: #, Negative: #)</th></tr><tr><td colspan="4">Submit feedback: <input type="text" name="comment" size="100" /> <input type="radio" name="feed_rate" value="3">0 <input type="radio" name="feed_rate" value="1">1 <input type="radio" name="feed_rate" value="2">2 <button type="button">Submit</button></td></tr><tr><th>Rating</th><th>Comment</th><th>From</th><th>Date</th></tr></tbody></table></form>');

        var profileID = window.location.href.split('profile/')[1].split('/')[0];

        $.get(main_url + 'forum/' + forumID + '/', function (data) {
            $('table.posts:not(#announcement_list) tr[class*="row"]', data).each(function () {
                var userID = $(this).find('td.c_cat-title a').text().split('~')[0];
                var rating = $(this).find('td.c_cat-title a').text().split('~')[1];
                var comment = $(this).find('div.description').text();
                var userHref = $(this).find('td.c_cat-starter a').attr('href');
                var userText = $(this).find('td.c_cat-starter a').text();
                var date = $(this).find('div.t_lastpostdate').text();

                if (profileID === userID) $('#feedback tbody').append('<tr><td>' + rating + '</td><td>' + comment + '</td><td><a href="' + userHref + '">' + userText + '</a></td><td>' + date + '</td></tr>');
            });
        });

        $('#feedback button').click(function () {
            var userID = window.location.href.split('profile/')[1].split('/')[0];
            var description = $('input[name="comment"]').val();
            var rating = $('input[name="feed_rate"]:checked').val();
            var title = userID + '~' + rating;

            $.get(main_url + 'post/?type=1&mode=1&f=' + forumID, function (data) {
                var ast = $('input[name="ast"]', data).val();
                var xc = $('input[name="xc"]', data).val();

                $.post(main_url + 'post/', $.extend({
                    mode: 1,
                    type: 1,
                    ast: ast,
                    f: forumID,
                    xc: xc,
                    sd: 1,
                    title: title,
                    description: description,
                    post: description + '~' + title
                }));
            });
        });
    }
</script>

这是我使用它的地方:http://s1.zetaboards.com/Cory/profile/62973/

使用测试账号登录:

用户名:测试

密码:Test1

【问题讨论】:

  • 您确定用户名和密码不是小写的吗?您真的希望人们登录您的网站并在论坛脚本中摆弄以发现错误吗?
  • $.post 中的type 参数,为什么要在$.extend() 中?
  • 我上面贴的用户名和密码是正确的,而且是测试账户,所以人们可以提交表单并自己查看错误。
  • 我认为是错误,它替换了jQuery内置函数$.type()
  • 你是说我不应该使用$.extend,因为使用它会将'type'视为$.type()?这是一个类似使用该函数并且似乎可以工作的脚本:z3.ifrm.com/313/104/0/p366373/form_script.js

标签: javascript jquery forum


【解决方案1】:

您正在用值 1 覆盖 jQuery 内置函数 $.type。 $.post 通话中$.extend({}) 的目的是什么?这就是导致错误的原因。

用这个替换它:

$.post(main_url + 'post/', {
      mode: 1,
      type: 1,
      ast: ast,
      f: forumID,
      xc: xc,
      sd: 1,
      title: title,
      description: description,
      post: description + '~' + title
});

不带第二个参数调用$.extend()会覆盖jQuery对象的默认属性。

【讨论】:

  • +1 - 我发现了同样的事情。绝对是一个严重的问题。
猜你喜欢
  • 1970-01-01
  • 2018-12-01
  • 2012-09-29
  • 1970-01-01
  • 2011-12-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多