![](/img/trans.png)
[英]Javascript Uncaught ReferenceError: Function is not defined
[英]Javascript - Uncaught ReferenceError: function is not defined
我在Javascript方面相對較新,並且有一個頁面在onkeyup
上調用javascript函數,但是當該頁面引發異常時, Uncaught ReferenceError: validate is not defined
。
<script type="text/javascript">
function validate(id){
alert(id);
$.ajax({
url: "http://example.com/restaurant/submit/verify",
type: "POST",
dataType: 'json',
data: {
field: id,
content: $('#' + id).val()
}
success: function(data){
alert(data);
if(data.status == "PASSED"){
$('#' + id).removeClass('has-error');
$('#' + id).addClass('has-success');
} else if(data.status == "FAILED") {
$('#' + id).removeClass('has-success');
$('#' + id).addClass('has-error');
$('#' + id + ' div').append('<span class="help-inline">' + data.error + '</span>')
}
}
});
}
</script>
非常感謝您的幫助,如果您需要更多信息,請隨時詢問。 感謝您提供的所有幫助。
您忘記了逗號和分號:
function validate(id){
alert(id);
$.ajax({
url: "http://example.com/restaurant/submit/verify",
type: "POST",
dataType: 'json',
data: {
field: id,
content: $('#' + id).val()
}, // Here
success: function(data){
alert(data);
if(data.status == "PASSED"){
$('#' + id).removeClass('has-error');
$('#' + id).addClass('has-success');
} else if(data.status == "FAILED") {
$('#' + id).removeClass('has-success');
$('#' + id).addClass('has-error');
$('#' + id + ' div').append('<span class="help-inline">' + data.error + '</span>'); // and here
}
}
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.