如果我尝试这样做,我会收到此错误:
if (old in sentence) == True:
Uncaught TypeError: Illegal invocation
如果我尝试这样做,我会收到此错误:
$(document).on('input', '#search-inp', (e) => {
$.ajax({
type: 'POST',
url: '/search/',
dataType: 'json',
data: {
input: $('#search-inp').val(),
csrfmiddlewaretoken: $('input[name=csrfmiddlewaretoken]'),
},
success: function(data) {
console.log(data);
}
});
});
403: Forbidden
$(document).on('input', '#search-inp', (e) => {
$.ajax({
type: 'POST',
url: '/search/',
dataType: 'json',
processData: false,
contentType: false,
data: {
input: $('#search-inp').val(),
csrfmiddlewaretoken: $('input[name=csrfmiddlewaretoken]'),
},
success: function(data) {
console.log(data);
}
});
});
可能是什么问题? 非常感谢您的帮助。谢谢
答案 0 :(得分:1)
很抱歉打扰了大家。
$(document).on('input', '#search-inp', (e) => {
$.ajax({
type: 'POST',
url: '/search/',
dataType: 'json',
data: {
input: $('#search-inp').val(),
csrfmiddlewaretoken: $('input[name=csrfmiddlewaretoken]').val(),
},
success: function(data) {
console.log(data);
}
});
});
我这样做了:csrfmiddlewaretoken: $('input[name=csrfmiddlewaretoken]')
但应该这样做:csrfmiddlewaretoken: $('input[name=csrfmiddlewaretoken]').val()