javascript - Unexpected character error in JQuery ajax function -


i have 'unexpected character error' problem, jquery ajax code looks that:

 function test(){         if(true){         $.ajax({             type: 'post',             url: 'test.php',             datatype: 'json',             data: {                 godot: 'godot',                 jobadze: 'jobadze'             },             success: function(data){                 alert(data);             },             error: function(jqxhr, textstatus, errorthrown) { alert("error status: "+textstatus+"\nmessage: "+errorthrown);             }         }); 

and php code:

<?php echo 'test'; ?> 

it should alert "test", calls error. going on?

you wrote datatype: 'json', php script required return valid json. since you're not, gets error when tries parse response json, , reports error.

you should use json_encode:

<?php echo json_encode('test'); ?> 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -