Otto Otto - 3 months ago 13
Ajax Question

SyntaxError: Unexpected end of JSON input

I can record data in my db but ajax loading doesn't inter in success method. What's the problem?

error: "SyntaxError: Unexpected end of JSON input
at Object.parse (native)
at n.parseJSON "


if ($type=="add_user"){
$stmt=$db->prepare("INSERT INTO newsletter_utenti(email,abilitato,nome,cognome,lingua,lista,data_creazione,unsubscribe) VALUES('$new_email',1,'$new_nome','$new_cognome','$new_lingua','manual',now(),0)");
if (!$stmt) {


var nome = $('#nome').val();
var cognome = $('#cognome').val();
var email = $('#email').val();
var lingua = $('#lingua').val();
var dataString = 'nome='+nome+'&cognome='+cognome+'&email='+email+'&lingua='+lingua+'&type=add_user';
success:function(result) {
error:function(xhr,status,error) {

$('#adduser').submit(function (){
return false;


<form name="adduser" id="adduser" method="GET" action="#">
<div class="col-md-3">
<div class="form-group m-b-30">
<input class="form-control" type="email" id="email" name="email" placeholder="indirizzo e-mail" email required>
<div class="col-md-3">
<div class="form-group m-b-30">
<input class="form-control" type="text" id="nome" name="nome" placeholder="nome">
<div class="col-md-3">
<div class="form-group m-b-30">
<input class="form-control" type="text" id="cognome" name="cognome" placeholder="cognome">
<div class="col-md-3">
<div class="form-group m-b-30">
<select class="form-control" id="lingua" name="lingua">
<option value="it">IT</option>
<option value="en">EN</option>
<input type="submit" class="btn btn-embossed btn-primary m-r-20" id="salvaBtn" value="Aggiungi utente"></input>
<div id="status_text" /></div>


your jquery ajax call should include

dataType: 'html',

to explicitly state that the data coming back from the server is html

in fact you're taking result and putting it straight into the DOM node with id statusText

Then you have to fix a major issue: your PHP script is not returning (echoing) any data !

Bottom note: you really should use mysqli for your db queries and also use prepared statements to build up the query (instead building up the SQL query by concatenating strings).