I am relatively new at Javascript, and I have a page that calls a javascript function on onkeyup
, but when called it throws an exception, 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>
Any help is greatly appreciated, if you need more info, don't hesitate to ask. Thanks for any and all help.
You forgot a comma and a semicolon:
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
}
}
});
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.