node.js - 连接到 Node.js 服务器时出错... parsererror SyntaxError: Unexpected token '<'
问题描述
我试图将输入值发送到我的节点服务器 app.js 使用 ajax
当我单击按钮时突然出现错误
这是我的html
<body>
<input type="text" name="username" id="username"/><br><br>
<input type="password" name="password"/><br><Br>
<button id="SubmitBtn" type="submit">Submit</button>
</body>
我的阿贾克斯
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script>
$(document).ready(function () {
$('#SubmitBtn').click(function (event) {
var username = document.getElementById('username').value;
$.ajax({
url: 'http://localhost:3000',
data:{username},
dataType: "jsonp",
jsonpCallback: "_testcb",
cache: false,
timeout: 5000,
success: function(data) {
alert(data);
},
error: function(jqXHR, textStatus, errorThrown) {
alert('Error connecting to the Node.js server... ' + textStatus + " " + errorThrown);
}
});
});
});
</script>
我的 app.js
var http = require('http');
http.createServer(function (req, res) {
var username = req.body.username;
console.log(username);
//do whatever you want
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('_testcb(\'{"message": "Welcome! Node.js Responding!"}\')');
}).listen(80)
这是错误信息
连接到 Node.js 服务器时出错... parsererror SyntaxError: Unexpected token '<'
解决方案
推荐阅读
- python-3.x - 一维元组到二维numpy数组
- android - Android 原生依赖管理
- javascript - 如何在不知道键的情况下使用 javascript/jquery 从多维 json 数组中检索值?
- jquery - 可编辑的小部件在 jQuery tablesorter 中没有响应
- python - “TypeError:不允许使用 `tf.Tensor` 作为 Python `bool`。” 在数据集上调用地图函数时
- python - 使用数据框中的条件删除重复项
- python - 如何从链接中提取经度和纬度
- angular7 - 无法使用 Angular 7 中的链接登录
- android - 如何在 XML 中添加 OR 运算符?
- terraform-provider-azure - Terraform azure 提供程序的 powershell 模块版本依赖项是什么?