【发布时间】:2021-07-30 18:31:54
【问题描述】:
我正在尝试在 nodeJs 中使用 Ajax 发出 POST 请求。当我运行函数alert(status) 时会弹出说parseerror。这个 Ajax 调用有什么问题?
function ajaxmagic() {
$.ajax({
url : 'FetchSongs.php',
type : 'POST',
data : {username: "maxolgin"},
dataType: "json",
success : function (result) {
var i;
for (i = 0; i < result.length; i++) {
var table = document.getElementById("myMixTable");
table.style.borderCollapse = "seperate"
var rowCount = table.rows.length;
console.log(table.rows.length)
var row = table.insertRow(0);
var row2 = table.insertRow(1);
var cell1 = row.insertCell(0);
cell1.rowSpan = "2"
cell1.setAttribute("class", "MixImage")
var image = document.createElement("img");
image.style.padding = "0px 0px 0px 0px"
cell1.appendChild(image)
var cell2 = row.insertCell(1);
cell2.style.width = "300px"
var title = document.createElement("td");
title.innerHTML = result[i].songTitle
cell2.appendChild(title);
var artistCell = row2.insertCell(0);
var artistTitle = document.createElement("td");
artistTitle.style.fontSize = "13px"
artistCell.appendChild(artistTitle);
var timestampCell = row.insertCell(2);
timestampCell.rowSpan = "2"
timestampCell.style.horizAlign = "right"
var timestamp = document.createElement("td");
timestamp.style.horizAlign = "right"
timestampCell.appendChild(timestamp);
}
},
error : function (jqxhr, status, exception) {
alert(status);
}
});
}
【问题讨论】:
-
检查网络选项卡和您的后端日志以了解请求失败的原因
-
你在 node.js 中做这个?
-
@law 很确定。这是一个 .js 文件