I'm trying to get an ajax request running, but I get a parsererror. This is my Javascript Code:
$.ajax({
type: 'POST',
url: 'insertuser.php',
dataType: 'json',
data: {
nickname: $('input[name=nickname]').val(),
passwort: $('input[name=passwort]').val()
},
success : function(data){
console.log(data);
},
error : function(XMLHttpRequest, textStatus, errorThrown) {
console.log("XMLHttpRequest", XMLHttpRequest);
console.log("textStatus", textStatus);
console.log("errorThrown", errorThrown);
}
});
Thats the php file:
$return['error'] = false;
$return['msg'] = "juhuuu";echo json_encode($return);
This is the console.log:
XMLHttpRequest Object textStatus parsererror errorThrown SyntaxError
Thats what the .php echos: {"error":false,"msg":"juhuuu"}
I hope someone has an idea :)
var str = $(this).serialize();
adn in phpparse_str($_POST["data"],$array);
– NullPoiиteя Oct 23 '12 at 8:55header('Content-Type: application/json');
? – migg Oct 23 '12 at 9:40