我不知道为什么我的代码在进行ajax调用时发出错误而没有响应或工作。我在一个html文件上运行它。我接受了这个函数 - 来自另一个stackoverflow的getParameterByName()answer.tweet-container标签是在这个脚本之外的下面的代码和一个空的division.I尝试了一些jquery。
<script>
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
$(document).ready(function(){
console.log("working");
var query = getParameterByName("q")
// console.log("query");
var tweetList = [];
function parseTweets(){
if (tweetList == 0){
$("#tweet-container").text("No tweets currently found.")
} else {
//tweets are existing, so parse and display them
$.each(parseTweets, function(key, value){
//console.log(key)
// console.log(value.user)
// console.log(value.content)
var tweetKey = value.key;
var tweetUser = value.user;
var tweetContent = value.content;
$("#tweet-container").append(
"<div class=\"media\"><div class=\"media-body\">" + tweetContent + "</br> via " + tweetUser.username + " | " + <a href="#">View</a> + "</div></div><hr/>"
)
})
}
}
$.ajax({
url:"/api/tweet/",
data:{
"q": query
},
method: "GET",
success:function(data){
//console.log(data)
tweetList = data
parseTweets()
},
error:
function(data){
console.log("error")
console.log(data)
}
})
});
</script>
&#13;
强文
答案 0 :(得分:0)
修复引号以解决语法错误:
router.delete('/driver/:id', function (req, res) {
Driver.findByIdAndRemove(req.params.id, function (err, driver) {
if (err) return res.status(500).send("There was a problem deleting the driver.");
res.status(200).send("Driver: " + driver.name + " was deleted.");
});
});
router.delete('/admin/:id', function (req, res) {
Admin.findByIdAndRemove(req.params.id, function (err, admin) {
if (err) return res.status(500).send("There was a problem deleting the admin.");
res.status(200).send("Admin: " + admin.name + " was deleted.");
});
});