开发者

$.ajax throwing weird "Uncaught TypeError: Illegal invocation"

开发者 https://www.devze.com 2023-01-26 18:53 出处:网络
I have some jQuery code which is throwing a really weird error. Google Chrome calls the error 开发者_运维问答Uncaught TypeError: Illegal invocation and says it is thrown in c.extend.param.e of jquery-

I have some jQuery code which is throwing a really weird error. Google Chrome calls the error 开发者_运维问答Uncaught TypeError: Illegal invocation and says it is thrown in c.extend.param.e of jquery-1.4.4.min.js line 144, but backtraces it to my $.ajax call, which looks like this:

$.ajax({
   url: target,
   type: method,
   dataType: 'json',
   data: sendData,
   success: function(result) {
       if (result.redirect) {
           window.location = result.redirect;
       }
       else {
           for (var i in result) {
                if ($(i).size()) {
                    $(i).html(result.i);
                }
            }
        }
    }
});

Another question on SO which looks a bit like this attributes it to using $ without enclosing it in a jQuery function properly, but I'm pretty sure that's not my error this time, because I've been careful.


Problems is here:

event.preventDefault();
var data = $.extend({
    referrer: window.location, <-- window.location is an object,
                                   should be window.location.href
    href: $(this).attr('href')
}, options.linkData);
loadPage(options.linkUrl, options.linkMethod, data);

Changing this makes it work, reason it breaks?

<jQUery1.4.4 at line 6079>
s[ s.length ] = encodeURIComponent(key) + "=" + encodeURIComponent(value)

encodeURIComponent does not like the window.location object as it only takes strings.

See: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/encodeURIComponent


try with jQuery.param with traditional parameter in true

documentation of param
modified

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号