Reputation: 9165
Hello It took hours now and I don't have a clue whats going on here. I always get the following error, when i send the ajax request with jquery 1.8:
"SyntaxError: invalid label"
This is my code...
$(document).ready(function() {
$("#create-workspace-button").click(function () {
show_dialog($(this));
})
$("#submit-create-workspace").live("click", function(event){
event.preventDefault();
category= $("#id_workspace_category").val();
workspace_name=$("#id_workspace_name").val()
var json_data = JSON.stringify({
"cat":category,
"workspace_name":workspace_name
})
$.ajaxSetup({
headers: {
'X-CSRFToken': $("input[name=csrfmiddlewaretoken]").val()
}
})
$.ajax({
type:'POST',
data:json_data,
url: '/workspace/create/',
success: function(data) {
alert('hi')
},
error: function(jqXHR, textStatus, errorThrown)
{
//here a label error happens...i dont know why
console.log(errorThrown)
}
})
});
$("#close").click(function () {
close_dialog($(this));
})
function close_dialog(thiz){
$(thiz).fadeOut(function(){
$('#layer,.form-submit-dialogbox').fadeOut();
})
}
function show_dialog(thiz){
$('#layer,.form-submit-dialogbox, #close').fadeIn();
}
})
edit "JSON.stringify(" was missed out...but same error
Upvotes: 0
Views: 4773
Reputation: 9165
When the ajax part looks like this it works...
$.ajax({
type : 'POST',
url : '/workspace/create/',
async: false,
dataType : 'json',
cache:false,
data: {
cat:category,
workspace_name:workspace_name
},
success : function(data){
//alert(data[0].title);
},
error: function(){
console.log('problems with data transfer');
}
});
Upvotes: 0
Reputation: 281495
Are you asking about a syntax error or a reference error? You've edited the code but not the title...
Your reference error could be because you're referring to the global console
object, which in some browsers only exists when the console is open.
Your syntax error could be because of the extra closing parenthesis )
at the very end of your code, but without seeing the wider context it's hard to tell.
Upvotes: 1