2011-03-07 50 views
3

为什么我收到此错误:为什么我在jQuery 1.4.4.min文件中出现意外的令牌错误?

Uncaught SyntaxError: Unexpected token < 
c.b.extend.globalEval       jquery-1.4.4.min.js:32 
c.extend.httpData        jquery-1.4.4.min.js:144 
c.extend.ajax.L.w.onreadystatechange   jquery-1.4.4.min.js:140 

此错误不指出我在我的JS一个地方,是触发这一问题。只是jQuery的min文件。

如何调试并修复它?

Edit1:下面是围绕此错误调用堆栈的一些截图。不过还是不确定,哪个文件有被jQuery调用的语法错误。

enter image description here enter image description here enter image description here

编辑2:

下面是我的一些AJAX的要求:

$('form#project-ajax-form').submit(function(){ 
    if(compv.steps.selectedClient.id != null){ 
    $('input#project_client_id').val(compv.steps.selectedClient.id); 
     console.debug("Project Client Value: " + $('input#project_client_id').val()); 
     return true; 
    } 
    console.debug("Project Client Value not found"); 
    compv.tools.clientError(); 
    return false; 
});  
$('#project-ajax-form') 
     .bind("ajax:success", function(evt, data, status, xhr){ 
     compv.updateStepView('project', xhr); 
}); 

$('#client-ajax-form') 
    .bind("ajax:success", function(evt, data, status, xhr){ 
    console.log("Calling Step View"); 
    compv.updateStepView('client', xhr); 
}); 

$('form#stage-ajax-form').submit(function(){ 
if(compv.steps.selectedProject.id != null){ 
$('input#stage_project_id').val(compv.steps.selectedProject.id); 
    console.debug("Stage Project Value: " + $('input#stage_project_id').val()); 
    return true; 
} 
console.debug("Stage Project Value not found"); 
compv.tools.clientError(); 
return false; 
}); 
$('#stage-ajax-form') 
    .bind("ajax:success", function(evt, data, status, xhr){ 
    compv.updateStepView('stage', xhr); 
}); 

$.ajaxSetup({ 
    beforeSend: function(xhr) { 
    xhr.setRequestHeader("Accept", "text/javascript"); 
    } 
}); 

$('.ajax-form') 
.bind("ajax:success", function(evt, data, status, xhr){ 
    var $form = $(this); 
    console.log("Form Success: %s", $(this).attr('id')); 

    // Reset fields and any validation errors, so form can be used again, but leave hidden_field values intact. 
    $form.find('textarea,input[type="text"],input[type="file"]').val(""); 
    $form.find('div.validation-error').empty(); 
}) 
.bind("ajax:failure", function(evt, xhr, status, error){ 
    var $form = $(this), 
     errors, 
     errorText; 
    console.log("Form Failure: %s", $(this).attr('id')); 

    try { 
    // Populate errorText with the comment errors 
    errors = $.parseJSON(xhr.responseText); 
    } catch(err) { 
    // If the responseText is not valid JSON (like if a 500 exception was thrown), populate errors with a generic error message. 
    console.error("Server Error for Form: %s", $(this).attr('id')); 
    errors = {"Server Error": "Please reload the page and try again"}; 
    } 

    // Build an unordered list from the list of errors 
    errorText = "There were errors: \n<ul>"; 

    for (error in errors) { 
    errorText += "<li>" + error + ': ' + errors[error] + "</li> "; 
    } 

    errorText += "</ul>"; 

    // Insert error list into form 
    var errorDiv = $form.find("div.validation-error"); 
    errorDiv.html(errorText); 
    errorDiv.show(300); 
}); 
+0

你应该能够看到调用堆栈,因此什么导致了错误,在脚本调试器,例如Chrome中内置的一个。 – 2011-03-07 15:02:10

+0

@jamietre对不起,如果这是一个愚蠢的问题,但我如何看到在OS X上的Chrome调用堆栈?如在哪里,我准确地看起来在哪里?谢谢。 – marcamillion 2011-03-07 15:04:01

+0

右键单击“检查元素”脚本,然后在右侧有一个“调用堆栈”部分。如果脚本调试器在发生错误时处于打开状态,则它已经存在。 – 2011-03-07 15:04:28

回答

3

调用堆栈显示,jQuery是从响应AJAX请求调用eval

您打电话给getScript查找带语法错误的Javascript文件。


要回答你的问题,规定,你可以通过切换到jQuery的调试版本(不.min),并使用调试器,如萤火虫或Chrome的开发者工具调试此。

+0

如何找到语法错​​误的位置? – marcamillion 2011-03-07 15:02:58

+2

检查Firebug或Chrome中的AJAX响应。 – SLaks 2011-03-07 15:05:42

+0

我已经更新了我的调用堆栈截图的问题。不知道如何找到正在调用语法错误的脚本。这是我第一次这样做,所以如果问题非常明显,我表示歉意。我究竟做错了什么 ? – marcamillion 2011-03-07 15:30:21

相关问题