我需要AJAX调用,一个用于GET,一个用于POST。我的GET请求工作正常,但是当我调用我的POST请求时,它会抛出Uncaught TypeError: Illegal invocation at jquery.js:9508
。我的整个代码如下所示,但失败的部分是click
上的$('div#save
函数,而成功的GET在('div#edit')
上。
我检查了我的后端,它甚至没有在POST上点击它。有什么问题?
$(document).ready(function(){
$('div#save').click(function(e){
e.preventDefault();
new_data = {
first_name: $('input#first_name').val(),
surname: $('input#surname').val(),
degree: $('input#degree').val(),
location: $('input#location').val(),
availability: $('input#availability'),
status: $('select#status').val(),
bio: $('textarea#bio').val()
};
$.ajax({
method: 'POST',
dataType: 'json',
url: '/update-freelancer/',
data: new_data,
success: function(){
$('h1#name').text(data['first_name'] + " " + data['surname'].substring(0,1) + ".");
$('span#degree_text').text(data['degree']);
$('span#location_text').text(data['location']);
$('span#availability_text').text(data['availability']);
$('span#status_text').text(data['status']);
$('span#bio_text').text(data['bio']);
},
error: function(){
console.log("Oh no!");
}
});
});
$('div#cancel').click(function(e){
e.preventDefault();
$('div.save').hide();
$('div#edit').show();
$('h1#name').show();
$('span#degree_text').show();
$('span#location_text').show();
$('span#availability_text').show();
$('span#status_text').show();
$('span#bio_text').show();
$('input#first_name').hide();
$('input#surname').hide();
$('input#degree').hide();
$('input#location').hide();
$('input#availability').hide();
$('select#status').hide();
$('textarea#bio').hide();
});
$('div#edit').click(function(e){
e.preventDefault();
$('div#edit').hide();
$('div.save').css('display', 'inline-block');
$('h1#name').hide();
$('span#degree_text').hide();
$('span#location_text').hide();
$('span#availability_text').hide();
$('span#status_text').hide();
$('span#bio_text').hide();
$('input#first_name').show();
$('input#surname').show();
$('input#degree').show();
$('input#location').show();
$('input#availability').show();
$('select#status').show();
$('textarea#bio').show();
$.ajax({
method: 'GET',
url: '/get-freelancer-details/',
dataType: 'json',
success: function(data){
console.log(data['surname']);
$('input#first_name').val(data['first_name']);
$('input#surname').val(data['surname']);
$('input#degree').val(data['degree']);
$('input#location').val(data['location']);
$('input#availability').val(data['availability']);
$('select#status').val(data['student_type']);
$('textarea#bio').val(data['bio']);
}});
});
});