JQuery AJAX Call Error

JQuery AJAX Call Error

Greetings,

I have an AJAX piece that is being sent to a PHP file. Below is the code for it. For some reason, I get the following error:


allery.js:31 failed to send AJAX POST
gallery.js:32 200
gallery.js:33 SyntaxError: Unexpected token U(…)
gallery.js:34 User
What am I doing wrong? On another note, how do I send a JS array over to PHP side and then parse it? Is it possible to send an array of arrays?

Here is the snippet:

  1. $.ajax({
  2. type: "POST",
  3. url: "write_db.php",
  4. cache: false,
  5. //contentType: false,
  6. dataType: "json",
  7. data: {"name":"User"},
  8. success: function(result) {
  9. console.log("Successfully sent an AJAX POST to write_db.php ")
  10.              },
  11.              error: function (xhr, ajaxOptions, thrownError) {
  12.              console.log("failed to send AJAX POST");
  13.                  console.log(xhr.status);
  14.                  console.log(thrownError);
  15.                  console.log(xhr.responseText);
  16.                }
  17. });

Also, here is the write_db.php

  1. <?php 
  2. $decoded = $_POST['data'];
  3. echo($decoded);
  4. $jsonFile = fopen('slider.json','w+');
  5. fwrite($jsonFile, $decoded);
  6. fclose($jsonFile);
  7. ?>