learningprobs Posted August 25, 2016 Share Posted August 25, 2016 Hello, I am having a bit of an annoying problem. I am trying to get an error message returned as json from my php script, at the moment all I am getting is this error in the console: parsererror SyntaxError: Unexpected token < in JSON at position 10(…) I would have believed(based on what I researched) that this error was due to the dataType not being set properly, but it is. Here is page 1 ajax code: var video_title_php = document.getElementById('videoName').value; var video_description_php = document.getElementById('videoDescription').value; var video_category_php = document.getElementById('videoCategoryId').value; var video_uid = "<?php echo $id; ?>"; $.ajax({ url: 'index.php?page=producer_save_video.php', dataType: "json", data: { videoidurl:videoId, video_title:video_title_php, video_description:video_description_php, video_category:video_category_php, video_uid:video_uid }, type: 'POST', success: function (response) { $("#php_results").html(response); }, error: function(jqXHR, textStatus, errorThrown) { console.log(textStatus, errorThrown); } }) And this is the simple json text I am trying to output on the other page: <?phpecho json_encode(array('error' => 'Well done! Your video has been uploaded!')); ?> Any idea please? Thanks. Quote Link to comment Share on other sites More sharing options...
requinix Posted August 25, 2016 Share Posted August 25, 2016 Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted August 25, 2016 Share Posted August 25, 2016 Next to the JavaScript console, there's a network tab which shows the exact content of both the request and the response. Use it to debug problems like this. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.