Javascript $.post 抛出“非法调用”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11729442/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
$.post throwing "Illegal invocation "
提问by sinθ
Edit: None of the answers suggested so far have worked at all.
编辑:到目前为止建议的答案都没有奏效。
I'm running this call with django. The first time it runs, the server returns "n_usr" (which changes the form the user files in). The second time, it just throws an Illegal invocation
error.
我正在用 django 运行这个电话。第一次运行时,服务器返回“n_usr”(它改变了用户文件的形式)。第二次,它只是抛出一个Illegal invocation
错误。
function log_in () {
username = $('#usr_enter').val();
password = $('#pass_enter').val();
if(!n_usr){
$.post('/ajax/login',{password: password, username: username}, function(data) {
if(data == "n_usr"){
$('#new_user_entry').show('slow');
n_usr = true;
}
else {
}
})
}else {
password2 = $('#pass_re_enter');
penname = $('#pen_enter');
$.post('/ajax/login', {password: password, password2: password2, username: username, pen_name: penname, TN: "TN"}, function(data) {
if(data == "e_act"){
} else {
}
});
}
}
回答by Rocket Hazmat
In your else
, you have:
在您的 中else
,您有:
password2 = $('#pass_re_enter');
penname = $('#pen_enter');
Then you have:
然后你有:
{password: password, password2: password2, username: username, pen_name: penname, TN: "TN"}
You are getting Illegal invocation
because jQuery is trying to serialize the jQuery object for $.post
, and it can't. It's probably trying to call a string method, and is passing it a jQuery object as context, thus causing the error.
你得到的Illegal invocation
是因为 jQuery 试图序列化 jQuery 对象$.post
,但它不能。它可能试图调用一个字符串方法,并将一个 jQuery 对象作为上下文传递给它,从而导致错误。
You need to add .val()
.
您需要添加.val()
.
password2 = $('#pass_re_enter').val();
penname = $('#pen_enter').val();
回答by Hogan
Well you are not calling them the same -- the first time:
好吧,您不是第一次称它们为相同的:
$.post(url_base+'/ajax/login' ...
and the 2nd
和第二
$.post('/ajax/login', {....
Change the 2nd one to include url_base.
将第二个更改为包含 url_base。