jQuery Ajax未运行错误

I am trying to post form data to PHP through jQuery. Here is the code.

-------------HTML FORM--------------

<div id="createQuestionBlock">
    <form id="createQuestionForm" action="" method="POST">
        Question Code: <input id="code" class="createQuestionTextBox1" type="text" name="questionCode"><span id="invalid_1"></span><br>
        Question Name: <input id="question" class="createQuestionTextBox1" type="text" name="questionName"><span id="invalid_2"></span><br>
        Correct Answer: <input id="answer" class="createQuestionTextBox1" type="text" name="correctAnswer"><span id="invalid_3"></span><br>
        Option 1: <input id="option1" class="createQuestionTextBox2" type="text" name="option_1"><span id="invalid_4"></span><br>
        Option 2: <input id="option2" class="createQuestionTextBox2" type="text" name="option_2"><span id="invalid_5"></span><br>
        Option 3: <input id="option3" class="createQuestionTextBox2" type="text" name="option_3"><span id="invalid_6"></span><br>
        Option 4: <input id="option4" class="createQuestionTextBox2" type="text" name="option_4"><span id="invalid_7"></span><br>
        Option 5: <input id="option5" class="createQuestionTextBox2" type="text" name="option_5"><span id="invalid_8"></span><br>
        <span id="quizCreated"></span>
        <input type="Submit" id="questionSubmit" value="Create Question"></input>   
    </form>
</div>

----------------JAVA SCRIPT JQUERY HANDLING----------------

function SubmitFormCreationData() {
$("#createQuestionForm").submit(function(e) {
    e.preventDefault();

    alert("check1");

    $.ajax({
        url: 'InsertNewQuestion.php',
        data: $("#createQuestionForm").serialize(), 
        dataType: 'json',
        success: function(data) {
            alert("check2");

            var infoCorrect = data.infoCorrect;

            if (infoCorrect == 0) {
                alert("Quiz Created");
                window.setTimeout(delay,2000);
                return true;
            } else if (infoCorrect == 1) {
                $("#invalid_1").text(" Invalid!").show().fadeOut(2000);
                return false;
            } else if (infoCorrect == 2) {
                $("#invalid_2").text(" Invalid!").show().fadeOut(2000);
                return false;
            } else if (infoCorrect == 3) {
                $("#invalid_3").text(" Invalid!").show().fadeOut(2000);
                return false;
            } else if (infoCorrect == 4) {
                $("#invalid_4").text(" Invalid!").show().fadeOut(2000);
                return false;
            } else if (infoCorrect == 5) {
                $("#invalid_5").text(" Invalid!").show().fadeOut(2000);
                return false;
            } else if (infoCorrect == 6) {
                $("#invalid_6").text(" Invalid!").show().fadeOut(2000);
                return false;
            } else if (infoCorrect == 7) {
                $("#invalid_7").text(" Invalid!").show().fadeOut(2000);
                return false;
            } else {
                $("#invalid_8").text(" Invalid!").show().fadeOut(2000);
                return false;
            }    
        }
    });

    alert("check3");
});
}

------------PHP FILE-------------------

<?php
$con = mysql_connect("localhost","root","");

if (!$con) 
    die("ERROR: ".mysql_error());                   

$db_con = mysql_select_db("QuestionsDatabase",$con);

if (!$db_con) 
    die("ERROR: ".mysql_error());

$questionCode = $_POST['questionCode'];
$questionName = $_POST['questionName'];
$correctAnswer = $_POST['correctAnswer'];
$option_1 = $_POST['option_1'];
$option_2 = $_POST['option_2'];
$option_3 = $_POST['option_3'];
$option_4 = $_POST['option_4'];
$option_5 = $_POST['option_5']; 

$infoCorrect = 0;

if (CheckCodeField($questionCode) == false)
    $infoCorrect = 1;
else if (CheckQuestionAnswerField($questionName) == false)
    $infoCorrect = 2;
else if (CheckCorrectAnswerField($correctAnswer) == false)
    $infoCorrect = 3;
else if (CheckQuestionAnswerField($option_1) == false)
    $infoCorrect = 4;
else if (CheckQuestionAnswerField($option_2) == false)
    $infoCorrect = 5;
else if (CheckQuestionAnswerField($option_3) == false)
    $infoCorrect = 6;
else if (CheckQuestionAnswerField($option_4) == false)
    $infoCorrect = 7;
else if (CheckQuestionAnswerField($option_5) == false)
    $infoCorrect = 8;

if ($infoCorrect == 0) {
    $rowIDList = mysql_query("SELECT rowID FROM questions");

    $currentGreatestRowID = -1;

    $rowCount = 1;

    while($row1 = mysql_fetch_assoc($rowIDList)) {
        if ($currentGreatestRowID < $row1['rowID']) {
            $currentGreatestRowID = $row1['rowID'];
        }

        $rowCount++;  
    }   

    $currentRowID = $currentGreatestRowID+1;


    $sql = "INSERT INTO questions (rowID,questionCode,questionName,option_1,option_2,option_3,option_4,option_5,option_1_votes,option_2_votes,option_3_votes,option_4_votes,option_5_votes,correctAnswer,pollingStatus) 
    VALUES (".$currentRowID.",".$questionCode.",'".$questionName."','".$option_1."','".$option_2."','".$option_3."','".$option_4."','".$option_5."',0,0,0,0,0,".$correctAnswer.",0)";

    if (mysql_query($sql,$con)) {
        echo "Inserted values";
    }
    else {
        echo ("Could not insert values: ". mysql_error());
    }
}

/*echo "| ".false." | "."0 | ";
echo "CheckCodeField(questionCode) = ".CheckCodeField($questionCode).", ";
echo "CheckQuestionAnswerField(questionName) = ".CheckQuestionAnswerField($questionName).", ";
echo "CheckCorrectAnswerField(correctAnswer) = ".CheckCorrectAnswerField($correctAnswer).", ";
echo "CheckQuestionAnswerField(option_1) = ".CheckQuestionAnswerField($option_1).", ";
echo "CheckQuestionAnswerField(option_2) = ".CheckQuestionAnswerField($option_2).", ";
echo "CheckQuestionAnswerField(option_3) = ".CheckQuestionAnswerField($option_3).", ";
echo "CheckQuestionAnswerField(option_4) = ".CheckQuestionAnswerField($option_4).", ";
echo "CheckQuestionAnswerField(option_5) = ".CheckQuestionAnswerField($option_5).", ";
echo "infoCorrect = ".$infoCorrect;*/

$items = array('infoCorrect'=>$infoCorrect);

json_encode($items);    

mysql_close($con);

//-----------------functions--------------
function CheckCodeField($value) {
    $isCodeValid = true;

    if (is_numeric($value) == false)
        $isCodeValid = false;
    if ($value < 100000)
        $isCodeValid = false;
    if ($value > 999999) 
        $isCodeValid = false;

    return $isCodeValid;
}

function CheckQuestionAnswerField($value) {
    $isQAValid = true;

    if($value == "")
        $isQAValid = false;
    if($value == null)
        $isQAValid = false;
    for($LCV=0; $LCV<(count($value)-1); $LCV++) {
        if($value[$LCV] = "'")
            $isQAValid = false;
        if($value[$LCV] = '"')
            $isQAValid = false;
    }

    return $isQAValid;
}

function CheckCorrectAnswerField ($value) {
    $isAnswerValid = true;

    if (is_numeric($value) == false)
        $isAnswerValid = false;
    if ($value < 1)
        $isAnswerValid = false;
    if ($value > 5) 
        $isAnswerValid = false;

    return $isAnswerValid;
}
//----------------------------------------

?>

Now the problem is that I can see the first alert("check1") and the second alert("check3") but I cannot see the alert("check2") so my assumption is that the error is in the ajax form. I have tried running the php file directly from the html page and it works correctly. What is going wrong?

-after edit--

So I looked at what info the json encode sends after making the change of echoing the json encode. This is the information that is sent {"infoCorrect":1}. Shouldn't

else if (infoCorrect == 1) {
    $("#invalid_1").text(" Invalid!").show().fadeOut(2000);
    return false;
}

run since infoCorrect is 1.

--------------after edit 2------------------------------------------------------------------------------------------------------- Below is how I am calling the SubmitFormCreationData() function as shown above.

$(document).ready(function() {
     jQueryInitialization();

    ButtonsHandling();

    SubmitFormCreationData();

    setInterval(function() {UpdateData()}, 500);
 });

--------------LAST EDIT (FOUND SOLUTION)-----------------------------------------------------------------------------

Below is the code for the solution mentioned in the answer. Its not really a solution rather a workaround. I used post instead of ajax and it worked. Also make sure that your jQuery file is up to date.

function SubmitFormCreationData() {
$("#createQuestionForm").submit(function(e) {
    e.preventDefault();

    $.post("InsertNewQuestion.php", $("#createQuestionForm").serialize()).success(function(data) {
        var infoCorrect = data.infoCorrect;

        if (infoCorrect == 0) {
            alert("Quiz Created");
            window.setTimeout(delay,2000);
            return true;
        } else if (infoCorrect == 1) {
            $("#invalid_1").text(" Invalid!").show().fadeOut(2000);
            return false;
        } else if (infoCorrect == 2) {
            $("#invalid_2").text(" Invalid!").show().fadeOut(2000);
            return false;
        } else if (infoCorrect == 3) {
            $("#invalid_3").text(" Invalid!").show().fadeOut(2000);
            return false;
        } else if (infoCorrect == 4) {
            $("#invalid_4").text(" Invalid!").show().fadeOut(2000);
            return false;
        } else if (infoCorrect == 5) {
            $("#invalid_5").text(" Invalid!").show().fadeOut(2000);
            return false;
        } else if (infoCorrect == 6) {
            $("#invalid_6").text(" Invalid!").show().fadeOut(2000);
            return false;
        } else if (infoCorrect == 7) {
            $("#invalid_7").text(" Invalid!").show().fadeOut(2000);
            return false;
        } else {
            $("#invalid_8").text(" Invalid!").show().fadeOut(2000);
            return false;
        }        
    });
});
}

The entire response has to be a valid json string if you set dataType to json but you are echoing out text before the json this will cause jQuery to produce an error.

if (mysql_query($sql,$con)) {
    echo "Inserted values";
}

remove the echo, put any message in the json response, and make sure you output the json (echo json_encode($items);).

You have to echo out the json:

echo json_encode($items);

Use the post method instead of the ajax method. See final edit in the question.