SQL插入已完成,但ajax检索错误消息

I have the following javascript code:

var value = $.ajax({
        type: "POST",
        url: "receive.php",
        data: $('#something').serialize(),
        cache: false,
        async: true
    }).success(function(){
    }).error(function() {
        alert("not sent");
    });

and PHP

if(isset($_POST['the_thingy'])){

    $allowed = 100;

    $the_thingy = $mysqli->real_escape_string($_POST['the_thingy']);

    $query = "SELECT another thingy from the database";

    $the_thingy_length = strlen($the_thingy);

    if($the_thingy_length <= $allowed){


        $query = "INSERT INTO thingyes VALUES '$the_thingy'";
        $result = $mysqli->query($query);



    }

//amongst other queries and of the same "type"

basically what happens is that the insertion is done indeed but for some reason it appears as doubled in the database (2x a query done one single time). The ajax retrieves alert("not sent"); and the page refreshes (which is not supposed). What might be causing this? Other queries, code syntax, certain functions? All other ajax I use work just fine. Is this a known problem due to something specific? Thank you very much in advance!

For the double submission and page refresh, it sounds like you need to prevent the default action of the form:

$("form").on('submit', function(event) {
  // prevent the default submit
  event.preventDefault();

  // do your other stuff

  // your ajax call
  var value = $.ajax({
       ...
    });
});

If the entries get added correctly but you get to your error function just the same, it is possible that you have an error in your php that causes the script to exit with an error (somewhere after the insert section).

You should enable error handling and display to see it in the network tab of your browser tools (or disable the ajax temporarily to submit normally and see the error in the browser) or check the web-server error log for messages.