JQuery,意想不到的令牌u

时间:2013-07-31 01:12:12

标签: c# asp.net-mvc jquery

我的视图中有ajax表单,但是当我尝试提交时,我收到以下错误: Opera 12.16 控制台输出:

Error thrown at line 541, column 3 in <anonymous function: parseJSON>(data) in http://mysite/Scripts/jquery-1.9.1.js:
    return window.JSON.parse( data );
called from line 33, column 2 in onError(error, inputElement) in http://mysite/Scripts/jquery.validate.unobtrusive.js:
    var container = $(this).find("[data-valmsg-for='" + inputElement[0].name + "']"),
called via Function.prototype.apply() from line 818, column 3 in <anonymous function: proxy>() in http://mysite/Scripts/jquery-1.9.1.js:
    return fn.apply( context || this, args.concat( core_slice.call( arguments ) ) );
called from line 619, column 7 in <anonymous function: showLabel>(element, message) in http://mysite/Scripts/jquery.validate.js:
    this.settings.errorPlacement(label, $(element));
called from line 581, column 6 in <anonymous function: defaultShowErrors>() in http://mysite/Scripts/jquery.validate.js:
    this.showLabel(this.successList[i]);
called from line 377, column 5 in <anonymous function: showErrors>(errors) in http://mysite/Scripts/jquery.validate.js:
    this.defaultShowErrors();
called from line 326, column 4 in <anonymous function: form>() in http://mysite/Scripts/jquery.validate.js:
    this.showErrors();
called from line 72, column 5 in <anonymous function: validate>(event) in http://mysite/Scripts/jquery.validate.js:
    if (validator.form())
called via Function.prototype.apply() from line 3073, column 5 in <anonymous function: dispatch>(event) in http://mysite/Scripts/jquery-1.9.1.js:
    ret = ( (jQuery.event.special[ handleObj.origType ] || {}).handle || handleObj.handler )
called via Function.prototype.apply() from line 2749, column 4 in <anonymous function: elemData.handle>(e) in http://mysite/Scripts/jquery-1.9.1.js:
    return typeof jQuery !== core_strundefined && (!e || jQuery.event.triggered !== e.type) ?

我的表单:

@using(Ajax.BeginForm("action",
                       "controller",
                       null,
                       new AjaxOptions
                           {
                               HttpMethod = "Post",
                               InsertionMode = InsertionMode.InsertAfter,
                               OnComplete = "completeRequest",
                               UpdateTargetId = "update-div"
                           }, new { @id = "my-ajax-form" }))
{...}

我的带有completeRequest方法

的java脚本文件
$(document).ready(function () {
    initializeSubmit();
});    

function initializeSubmit(){
    $('#myinput').change(function() {
        alert(); // alert works and after that I get that big error in browsers console
        $('#my-ajax-form').submit();
    });
}

function completeRequest(data) {
        var result = $.parseJSON(data.responseText);

        // do stuff
    }

Google Chrome 浏览器的控制台输出:

ncaught SyntaxError: Unexpected token u       jquery-1.9.1.js:541
jQuery.extend.parseJSON                       jquery-1.9.1.js:541
onError                                       jquery.validate.unobtrusive.js:41
proxy                                         jquery-1.9.1.js:818
$.extend.showLabel                            jquery.validate.js:698
$.extend.defaultShowErrors                    jquery.validate.js:655
$.extend.showErrors                           jquery.validate.js:410
$.extend.form                                 jquery.validate.js:358
(anonymous function)                          jquery.validate.js:83
jQuery.event.dispatch                         jquery-1.9.1.js:3074
elemData.handle                               jquery-1.9.1.js:2750
jQuery.event.trigger                          jquery-1.9.1.js:2986
(anonymous function)                          jquery-1.9.1.js:3677
jQuery.extend.each                            jquery-1.9.1.js:648
jQuery.fn.jQuery.each                         jquery-1.9.1.js:270
jQuery.fn.extend.trigger                      jquery-1.9.1.js:3676
jQuery.fn.(anonymous function)                jquery-1.9.1.js:7403
(anonymous function)                          *******my-javascript-file.js:171******
jQuery.event.dispatch                         jquery-1.9.1.js:3074
elemData.handle                               jquery-1.9.1.js:2750

my-javascript-file.js:171 实际上是行,其中调用了提交:

function initializeSubmit(){
        $('#myinput').change(function() {
            alert(); // alert works and after that I get that big error in browsers console
171:       $('#my-ajax-form').submit();
        });
    }

这是实际的jquery源代码,它会抛出异常:

if ( !(eventHandle = elemData.handle) ) {
            eventHandle = elemData.handle = function( e ) {
                // Discard the second event of a jQuery.event.trigger() and
                // when an event is called after a page has unloaded
                return typeof jQuery !== core_strundefined && (!e || jQuery.event.triggered !== e.type) ?
        2750: jQuery.event.dispatch.apply( eventHandle.elem, arguments ) :
                    undefined;
            };
            // Add elem as a property of the handle fn to prevent a memory leak with IE non-native events
            eventHandle.elem = elem;
        }

jQuery 541

parseJSON: function( data ) {
        // Attempt to parse using the native JSON parser first
        if ( window.JSON && window.JSON.parse ) {
541:                    return window.JSON.parse( data );
//Uncaught SyntaxError: Unexpected token u
        }

这是jQuery的错误吗?或者可能是什么问题?我已经被困在这里大约几个小时了。

P.S。错误被抛出之前提交。表格尚未发布。

这是chrome调试器中的错误状态。 enter image description here

PPS 我发现了一个奇怪的解决方案:我为所有模型属性添加了@Html.ValidationMessageFor()帮助程序,并且我已成功发布表单,获得了服务器端和在控制器中达到我的突破点。还是无法理解这个问题是什么。

0 个答案:

没有答案