JQuery Ajax does not response to Node JS
JQuery Ajax does not response to Node JS
我有以下表单(在客户端):
<html>
<body>
<script>
$(document).ready(function() {
$.ajax({
url: "Search.html",
type: "POST",
dataType : "json",
success: function (result) {
console.log(result);
if(result.status == 200 && result.validationFailed ){
alert(result.message);
}
},
error: function(result){
console.log(result);
if(error.responseText == 'showAlert'){
alert( "Sorry, there was a problem!" );
}
}
})
});
}
</script>
<form action="/process_post" method="POST">
<select name="SearchTypes">
<option value="Author" selected>Author</option>
<option value="Mention">Mention</option>
<option value="Tag">Tag</option>
</select>
<input type="text" name="term">
<br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
在服务器端,我使用NodeJS根据数据库验证数据并回复客户端。我有一个数据库中没有数据的情况,我想告诉使用Ajax的用户数据不可用:
var query = connection.query(queryString, [term,term], function(err, rows) {
var res1 = {};
console.log(rows);
var tweet = JSON.parse(JSON.stringify(rows));
if (tweet.length == 0){
res1.status = 200;
res1.validationFailed = true;
res1.message = 'Empty data';
res.send(JSON.stringify(res1));
}else{
for(var i in tweet){
res.write("Author: ");
......
当我运行代码时,我不会收到警报。我实际上得到了以下内容:
{"status":500,"validationFailed":true,"message":"Empty data"}
你能帮我处理这个吗
您忘记在$.ajax.
相关文章:
- Node.js v6.2.0类扩展不是函数错误
- 如何使用 node.js 比较两个 json 数组
- 节点Js:How to catch a“;没有这样的文件或目录“;读取线模块出错
- Node.js - POST to iFrame?
- 为什么node.js不等到恢复完成(_search request in to elasticsearch)
- JQuery Ajax does not response to Node JS
- Node js readFile to String发出声音
- jQuery POST to Node.JS Fails
- uglifyjs - symfony assetic dump, path to node
- Node.js to JavascriptJquery 传递变量
- HTTPRequest to Node 服务器适用于 IE 8,但不适用于 IE 7
- 未捕获类型错误:Failed to execute 'appendChild'on 'Node&
- Large CSV to JSON/Object in Node.js
- 未捕获类型错误:Failed to execute 'appendChild'on 'Node&
- node.js xml to json objects
- Angular POST to Node Server
- Change node.js Buffer(BASE64) to jQuery
- AngularJS ng-repeat filter to child node
- Node.js Express res.json to html page?
- Node.js:我如何访问使用node-imap接收的电子邮件的“To”,“Body”和“From”字段?