自己用node写demo的时候遇到的
我的原程序是:
<script src="">
$('#login_form').on('submit', function (e) {
e.preventDefault()
var formData = $(this).serialize()
console.log(formData)
$.ajax({
url: '/login',
type: 'post',
data: formData,
dataType: 'json',
success: function (data) {
var err_code = data.err_code
// console.log('data', data);
if (err_code === 0) {
window.alert('登录成功!')
// 服务端重定向针对异步请求无效
// window.location.href = '/'
} else if (err_code === 1) {
// window.alert('邮箱或者密码错误')
window.alert(data.message)
} else if (err_code === 500) {
window.alert('服务器忙,请稍后重试!')
}
}
})
})
</script>
本来点击按钮之后,会有弹框,但是现在没有,我把script中的代码删了,只有一个console.log也不行,说明程序并没有执行标签中的代码,那就可能是我的script标签的问题?
我发现,这里的script里,比我以前写的多了一个src=""
,我就到mdn上面查,
是这样说的:
src
This attribute specifies the URI of an external script; this can be used as an alternative to embedding a script directly within a document.
官网地址
就是说,在script标签中,可以加入待执行的脚本,但是如果加了src,他会执行src里面的内容,不会执行脚本内容了。
所以,我的src虽然是空的,但是也会执行,所以我的脚本就不会执行了。
虽然是个很简单的问题,但是很细节