获取错误JSON.parse:尝试提交表单时出现意外字符

时间:2013-07-22 06:00:22

标签: jquery json asp.net-mvc-4

我在输入视频标题并尝试提交表单时收到错误“JSON.parse:意外字符”。我无法提交表单。请建议。

Firebug在jquery.js文件行号中显示错误。 541

parseJSON: function( data ) {
// Attempt to parse using the native JSON parser first
if ( window.JSON && window.JSON.parse ) {
**return window.JSON.parse( data );**  ---> Here (Line 541)
}
if ( data === null ) {
return data;
} 

@using (Html.BeginForm("SaveTrainerVideo", "Trainer", FormMethod.Post, new { @enctype = "multipart/form-data", @id = "Form_VideoGallery_Management" }))

    <span class="TrainerLabel">Upload Video<span class="MandatoryStar">*</span></span>
    <div style="position: relative; clear: both;">
        <input id="TrainerVideo" type="file" name="TrainerVideo" style="max-width: 91%" class="fileUploader" data-val="true" required="required" data-val-required="Please select video file for uploading." size="24px;" />

    </div>
    <div class="field-validation-error" id="showValid" style="display: none;">Please select video file for uploading.</div>
    <div id="progress" style="width: 60%; margin-top: 1%;">
        <div class="bar" style="width: 0%;"></div>
    </div>            

    <span class="TrainerLabel">Video Title<span class="MandatoryStar">*</span></span>
    @Html.TextBoxFor(m => m.VideoTitle, new { @class = "FitsomEditor", @style = "width:58%;" })
    <div class="field-validation-error" id="validTitle" style="display: none;">Please enter video title.</div>

    <div class="large-12 columns">
        <input id="btnSave" type="submit" class="button FitsomButton" value="Upload" onclick="return SetSaveValues()" />
    </div>
}


function SetSaveValues() {


    var File = document.getElementById('HasFile').value;
    var Title = document.getElementById('VideoTitle').value;

    if (Title != "" && File != "") {
        $("#showValid").hide();
        $("#validTitle").hide();
        return true;
    }
    else {
        if (File == null || File == '') {
            $("#showValid").show();
        }
        else {
            $("#showValid").hide();
        }
        if (Title == "") {
            $("#validTitle").show();
        }
        else {
            $("#validTitle").hide();
    }
        return false;
    }

}

1 个答案:

答案 0 :(得分:3)

试试这个

parseJSON: function( data ) {
   // Attempt to parse using the native JSON parser first
  if ( window.JSON && window.JSON.parse ) {
  return jQuery.parseJSON(data);
 }
if ( data === null ) {
   return data;
}